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:

python
name = "middle class boy"
age = 25
height = 5.9

Boom. 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:

TypeExampleWhat it is
int10, -5Whole numbers
float3.14, 99.99Decimal numbers
str"hello", 'Python'Text (use quotes!)
boolTrue, FalseYes/No logic

Wanna check? Use type():

python
print(type(age))     # → <class 'int'>
print(type(height))  # → <class 'float'>

Let’s code! Open day2.py

Type this in:

python
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 →

text
Hey Priya, you're 22 and scored 95.5!
Are you cool? True

f-strings are LIFE. Just put {variable} inside f"..." and it prints clean. No more "Hello " + name + "!" mess.


Input from user? Easy.

python
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:

python
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:

  1. Ask name
  2. Ask salary (float)
  3. Print: Hey middle class boy, your salary is $55000.75
  4. Then: As whole number: $55000

Here’s the code (type it yourself!):

python
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:

text
Enter name: Middle class boy
Enter salary: 55000.75
→ Hey Middle class boy, your salary is $55000.75
→ As integer: $55000

Common Oops Moments

MistakeWhat happensFix
int("hello")ValueErrorOnly convert numbers!
age = 25 print(age)SyntaxErrorNeed comma or new line
Forgetting quotesNameError"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:

python
a = 10
b = 3
print(a // b)  # → 3 (floor division!)


Comments

Post a Comment

Popular Posts