AlgoBazaAlgoBaza
Python for kids ยท Module 1

Lesson 4

Whole numbers, numbers with a dot and text

After this lesson: You'll meet three kinds of values: whole numbers, numbers with a dot and text - and see how they differ.

Video

?

The video for this lesson is coming soon.

Explanation

You can already print text and calculate. But did you know Python has different kinds of values? 7, 7.0 and "7" look similar, but they're three completely different things! ๐Ÿ”

Three kinds of values

KindWhat it looks likeExamplesPython calls it
a whole numberdigits, no dot7, 0, 2026, -3int
a number with a dotdigits with a dot2.5, 7.0, 0.1float
textanything in quotes"cat", "7", "2.5"str

First a story: Bajtek goes to the market.

Bajtek at the market ๐ŸŽฌ

Click Next to go step by step.

?Bajtek
Come and shop!๐Ÿง‘โ€๐ŸŒพ
๐ŸŽ๐ŸŽ๐ŸŽ3 piecesโš–๏ธ2.5 kg๐Ÿท๏ธ"Apples"
1

Three kinds of things

At the stall Bajtek sees three kinds of information: how many pieces (3 apples), how much something weighs (2.5 kg of plums) and what's written on the sign. In Python these are three kinds of values.

Step 1 / 8

The value sorter ๐Ÿ”

Every value passes under the scanner and drops into its bin. Watch for the dot and the quotes!

๐Ÿ”
?Bajtek
๐Ÿ”ค strtext
๐Ÿ”ข intwhole number
๐Ÿ”Ÿ floatnumber with a dot

Code

๐Ÿ–ฅ๏ธ Screen

1

The scanner reads every value that passes under it and says whether it's text, a whole number or a number with a dot. Click Next - the values will drop into their bins one by one.

Step 1 / 8

Three sevens on the screen

Watch what each print prints. The number 7 and the text "7" look the same on the screen - you only see the difference in the code.

โ€ฆ
?

Click the arrow - the computer runs the instructions in order, from top to bottom.

Code
1print(7)
2print(7.0)
3print("7")
Screen
โ–
1/4 ยท line 1 runs next

A dot, not a comma

In some countries people write 2,5, but in Python numbers with a dot are written with a dot: 2.5. A comma in print separates different values - that's why print(2,5) prints two numbers: 2 5.

A comma or a dot?

The first line has a comma - Python sees two numbers and puts a space between them. The second has a dot - it's one number, 2.5.

โ€ฆ
?

Click the arrow - you'll see what print puts between the values.

Code
1print(2,5)
2print(2.5)
Screen
โ–
1/3 ยท line 1 runs next
?

Which value is a number with a dot?

What comes out of a calculation?

  • a whole number with a whole number - a whole number: 3 + 4 is 7,
  • when there's even one number with a dot - the result has a dot too: 2 + 0.5 is 2.5, and 2 + 2.0 is 4.0,
  • text in quotes calculates nothing: "3 + 4" is just text.

The result sorter ๐Ÿ”

Python calculates first, and only the result goes under the scanner.

๐Ÿ”
?Bajtek
๐Ÿ”ค strtext
๐Ÿ”ข intwhole number
๐Ÿ”Ÿ floatnumber with a dot

Code

๐Ÿ–ฅ๏ธ Screen

1

The scanner reads every value that passes under it and says whether it's text, a whole number or a number with a dot. Click Next - the values will drop into their bins one by one.

Step 1 / 7

The results

Compare: where does the result have a dot, and where doesn't it?

Code
1print(3 + 4)
2print(2 + 0.5)
3print(2 + 2.0)
4print("3 + 4")
Screen
โ–
1/5 ยท line 1 runs next
?

What does print(5 + 1.0) print?

?

What does print(2,5) print?

Why different kinds?

Python calculates with numbers, and only prints and keeps text. When you know which kind you have, you also know what Python will do with it. You'll use this all the time in the next lessons!

Remember

  • A whole number (int) - no dot: 7, 0, -3.
  • A number with a dot (float) - with a dot: 2.5, 7.0. A dot, not a comma!
  • Text (str) - anything in quotes, even digits: "7".
  • When a calculation has a number with a dot, the result has a dot too: 2 + 2.0 is 4.0.

Now you can recognise every value! Time for the tasks. ๐Ÿ”

Tasks from the video

We solve them together in the video - pause it and try first on your own.

Practice tasks

Try to solve them without the video. Stuck? Every task has hints and an editorial.

Sign in to save your progress.