DAY-2 OF LEARNING PYTHON
Heyy! Day 2 let’s gooo!
So yesterday you nailed the setup — Python installed, VS Code ready, "Hello World" running like a champ. Now? Time to actually store stuff — like your name, age, marks, whatever. That’s where variables come in. Think of them as little sticky notes with data on them.
Let me show you real quick:
name = "middle class boy"
age = 25
height = 5.9Boom. That’s it. No drama. No int age = 25; like in C. Python just knows.
Okay, but what can we store?
4 main types for now:
| Type | Example | What it is |
|---|---|---|
| int | 10, -5 | Whole numbers |
| float | 3.14, 99.99 | Decimal numbers |
| str | "hello", 'Python' | Text (use quotes!) |
| bool | True, False | Yes/No logic |
Wanna check? Use type():
print(type(age)) # → <class 'int'>
print(type(height)) # → <class 'float'>Let’s code! Open day2.py
Type this in:
name = "Priya"
age = 22
score = 95.5
is_cool = True
print(f"Hey {name}, you're {age} and scored {score}!")
print("Are you cool?", is_cool)Run it →
Hey Priya, you're 22 and scored 95.5!
Are you cool? Truef-strings are LIFE. Just put {variable} inside f"..." and it prints clean. No more "Hello " + name + "!" mess.
Input from user? Easy.
user = input("What's your name? ")
print(f"Nice to meet you, {user}!")Warning: input() always gives a string. Even if user types 25, it’s "25".
So if you wanna do math:
age = input("Your age? ")
age = int(age) # ← convert!
print("Next year:", age + 1)Try typing 20 → Output: Next year: 21
Mini Project Time! (Your Exercise)
Make a salary printer:
- Ask name
- Ask salary (float)
- Print: Hey middle class boy, your salary is $55000.75
- Then: As whole number: $55000
Here’s the code (type it yourself!):
name = input("Enter name: ")
salary = float(input("Enter salary: "))
print(f"Hey {name}, your salary is ${salary}")
print(f"As integer: ${int(salary)}")Test it:
Enter name: Middle class boy
Enter salary: 55000.75
→ Hey Middle class boy, your salary is $55000.75
→ As integer: $55000Common Oops Moments
| Mistake | What happens | Fix |
|---|---|---|
| int("hello") | ValueError | Only convert numbers! |
| age = 25 print(age) | SyntaxError | Need comma or new line |
| Forgetting quotes | NameError | "hello" not hello |
Your Day 2 Checklist
- Created variables
- Used int, float, str, bool
- Tried input() + int()
- Used f-strings
- Ran the salary program
Tomorrow? → Day 3: Operators
We’re building a mini calculator! You’ll use:
- + - * / // %
- == != > <
- and or not
Sneak peek:
a = 10
b = 3
print(a // b) # → 3 (floor division!)


Excellent
ReplyDeleteThank you for this
ReplyDelete