Junior Codes
Message Harbour

Converting Text to Numbers in Python for Kids

Turn typed answers into real numbers with int() and float().

Start Wonderwild free with Pip

Try 5 starter activities free. Full access is ₹499 a year.

This mission is part of full access. The first missions are free to try.

Text to numbers, explained simply

Try adding "2" + "3" in Python and you get "23", not 5. That is because the quotes make them text, and adding text just sticks the pieces together.

int() turns text that looks like a whole number into a real number you can do maths with. float() does the same for numbers with a decimal point, like 2.5.

This matters most with input(), because answers always arrive as text. Wrap the input in int() when you expect a whole number.

Example: Count the lemonade cups

cups = int(input("How many cups? "))
price = 10
print(f"That costs {cups * price} rupees.")

Output

How many cups? 3
That costs 30 rupees.

Try this

  • Remove int() and run it again. What happens to the answer?
  • Ask for two numbers and print their total.
  • Type a word instead of a number and read the error. Later you will learn how to handle it.

Practise it in Wonderwild

“The lemonade counter”

Mission 9 in Message Harbour, one of 36 Python missions in Wonderwild.

Your child writes and runs real Python in the browser while Pip reacts to every line. Nothing to install. For ages 7+.

Start Wonderwild free with Pip

Try 5 starter activities free. Full access is ₹499 a year.

This mission is part of full access. The first missions are free to try.

Questions parents and kids ask

What is the difference between int() and float()?+

int() makes whole numbers like 4. float() makes numbers with a decimal part, like 4.75. Use float() for things like prices or heights.

Can I turn a number back into text?+

Yes, str(5) gives "5". That is useful when you want to join a number onto a message with +.

Prefer learning with a teacher?

Our live Python for Young Developers course teaches these ideas in small online classes led by a software engineer, with projects and feedback. Every live course also includes 12 months of full Wonderwild access for practice.

See the Python for Young Developers course