RisingCoder Full course โ†’
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.

Try it: fill the boxes yourself!

name = "Meera"   age = 11

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. ๐Ÿ”

Day 2 complete! Your boxes are packed. ๐Ÿ“ฆ

Tomorrow: maths superpowers and True/False questions.

Go to Day 3: Math Powers โ†’

๐ŸŽฎ Or test yourself in the free Python Arcade โ†’