Day 1Day 2Day 3Day 4
๐ฆ
FREE INTERACTIVE NOTES ยท DAY 2 OF 24
Magic Boxes That Remember ๐ฆ
A variable is a box with a name sticker. Put anything inside โ the computer remembers it for you.
1Boxes with name stickers
๐
Py: Imagine tiffin boxes with stickers: one says name, one says age. Whatever you put inside, Bittu remembers.
2Boxes can change!
Put something new in a box โ the old thing is gone. The last thing you put in wins.
๐ค
Bittu: I only remember the newest thing in each box. My memory is perfect but I don't do nostalgia.
3Different kinds of things (types)
Boxes can hold different kinds of things โ and Python knows which is which:
๐ str โ text in quotes: "hello" ๐ข int โ whole numbers: 42 ๐ฃ float โ decimal numbers: 3.14 โ
bool โ True or False
๐ฆ
Professor Hoot: Ask type(thing) whenever you're unsure. Even professionals do this daily!
4input() โ the computer asks YOU
So far you talk, Bittu listens. With input(), Bittu asks a question and waits for your answer:
๐
Py: The yellow โจ lines are what a person typed. input() waits as long as you need โ Bittu is patient.
5The sneaky trap: input gives TEXT
๐
Bugly: Heheheโฆ input() ALWAYS hands you text. "10" is not the number 10 โ watch this go wrong!
Fix it with int() โ it turns digit-text into a real number:
6Quick quiz! ๐ง
What does print("5" + "5") show?
๐ก With quotes they are TEXT. Plus glues text together: "5"+"5" = "55".
A player types their score into input(). What type arrives?
๐ก Always text! Wrap it: int(input("Score: ")) to do maths with it.
7Your mission ๐
Mission 1: Make boxes for your name, age and favourite game โ print all three.
Mission 2: Ask the user their age with input(), turn it into a number, and print their age NEXT year. (Hint: int, then + 1.)
Mission 3: Print type() of "10" and of 10. Spot the difference like a detective. ๐