Skip to content

Day 1 : Variable + if/else


🟢 Day 1 — Thinking Like a Computer (Foundations)

1️⃣ Why Are We Learning This?

Imagine you are talking to a very obedient but very dumb assistant.
It never guesses
It never assumes
It never understands meaning
It only follows exact instructions, step by step
That assistant is a computer.
💡 Programming = learning how to give clear, exact, unambiguous instructions
Python is just the language we use to talk to it.

2️⃣ How a Computer Thinks (Very Important)

A computer:
Reads code top to bottom
Executes one line at a time
Never skips lines
Never understands intent
Example (read carefully):
x = 10
x = 20
print(x)
👉 Output will be 20 Because the latest instruction wins.
🧠 A computer does not remember history. It only knows the current value.

3️⃣ Variables — Storing Information

Real-world analogy

Think of a labeled box.
Label = variable name
Value = what is inside the box
name → "Amit"
age → 22

Python example

name = "Amit"
age = 22

print(name)
print(age)

Important Rules

Variable names should describe the data
Python decides the type automatically
You don’t declare types like other languages

4️⃣ Data Types (Only What We Need Today)→ i love my wife

Numbers

x = 10 # integer
price = 99.5 # float

Text (String)

city = "Delhi"

Boolean (True / False)

is_active = True
🧠 Think of types as different kinds of boxes

5️⃣ Taking Input from User

So far, you are giving values.
Now let the user give values.
name = input("Enter your name: ")
print(name)

Important Truth (Critical for beginners)

input() always gives text, even if user types a number.
age = input("Enter age: ")
print(type(age)) # this is string, not number

Converting to number

age = int(input("Enter age: "))

6️⃣ Making Decisions — if / else

Real life example:
If traffic light is red → stop Else → go
Python works the same way.
age = int(input("Enter age: "))

if age >= 18:
print("Adult")
else:
print("Minor")

How computer evaluates this:

Check condition (age >= 18)
If True → run first block
If False → run else block
🧠 Computer does not know what “adult” means. It only checks true or false.

7️⃣ Indentation — Python’s Superpower

Python uses spaces, not brackets.
❌ Wrong
if age >= 18:
print("Adult")
✅ Correct
if age >= 18:
print("Adult")
🧠 Indentation tells Python which code belongs together

8️⃣ Common Beginner Mistakes (Read Carefully)

Forgetting to convert input to number
Using = instead of ==
Wrong indentation
Assuming computer “understands intention”
Example mistake:
if age = 18: # ❌ wrong
Correct:
if age == 18:

9️⃣ Practice Questions (Do These Seriously)

Do not jump to code immediately. Think first. Write steps on paper.

Q1

Print "Hello, Python" on the screen.

Q2

Store your name and age in variables and print them.

Q3

Take a number from user and print whether it is positive or negative.

Q4

Take a number and print whether it is even or odd.

Q5

Take two numbers and print the larger one.

Q6

Take age as input and print:
"Child" if age < 13
"Teen" if age between 13–19
"Adult" otherwise

Q7 (Thinking Question)

What happens if the user enters "abc" instead of a number? Why does the program crash?
(No fixing yet. Just observe.)

🔑 HINTS (Read Only If Stuck)

Use % operator to check even/odd
if, elif, else are mutually exclusive
Convert input using int()
Comparison operators: >, <, >=, <=, ==
Think in true / false, not English meaning

🔟 What You Should Be Able to Do Now

By end of Day 1, you should:
Understand how computer executes code
Store and update values
Take input from user
Make decisions using conditions
Predict output before running code

🧠 Reflection (VERY IMPORTANT)

Answer in words, not code:
Why does computer need exact instructions?
Why is input always a string?
What happens if indentation is wrong?
 
Want to print your doc?
This is not the way.
Try clicking the ··· in the right corner or using a keyboard shortcut (
CtrlP
) instead.