Free lesson · Module 1, lesson 5 of 8

Numbers, text and true or false

Tell whole numbers, decimals, text and True or False apart, use the seven arithmetic operators, and predict why "2" + "3" is not 5.

The video for this lesson is being prepared

About 10 minutes, narrated in English, Hindi and Odia. The notes and the quiz below are open now.

Lesson notes

Four kinds of values

  • Whole number, an integer: 42 (people on a bus); type(42) is int
  • Decimal, a float: 102.5 (petrol, ₹ a litre); type(102.5) is float
  • Text, a string, always in quotes: "Bhubaneswar"; type("Bhubaneswar") is str
  • True or False, a Boolean, capital first letter: True, False; type(True) is bool
  • print(type(42)) shows <class 'int'>

The seven arithmetic operators

  • + add, - subtract, * multiply: 6 * 7 is 42
  • / divide, always a float: 7 / 2 is 3.5, 6 / 2 is 3.0
  • // whole-number divide (full shares): 7 // 2 is 3
  • % remainder (what is left): 7 % 2 is 1
  • ** power: 2 ** 3 is 8
  • Order: brackets, then **, then * / // %, then + -; equal ranks go left to right

Quotes decide the kind

  • "2" + "3" joins two texts: 23, not 5
  • "ha" * 3 repeats text: hahaha
  • "2" + 3 (text plus a number) is an error

The trap

  • Numbers in quotes still add up: no. In quotes it is text, and plus joins it. Leave the quotes off to calculate

Try it in Google Colab or Visual Studio Code

  • print(17 // 5) and print(17 % 5) print 3 and 2
  • print(2 + 3) and print("2" + "3") print 5 and 23
  • print((10 - 4) / 2) and print(2 + 3 * 4 ** 2) print 3.0 and 50
  • print(29 // 4) and print(29 % 4) print 7 and 1
  • print(type("25")) and print(type(25)): compare the two

Lesson quiz

Checked in your browser. Nothing is sent or saved.

5 questions

Question 1 · easy

Ravi and four friends share an auto fare of ₹45 equally. What does this program print?

print(45 / 5)

Question 2 · easy

Nisha writes the value "7.5" (with the quotes) in her program. What kind of value is it?

Question 3 · medium

Nisha packs 50 eggs into trays that hold 12 eggs each. What does this program print?

eggs = 50
print(eggs // 12, eggs % 12)

Question 4 · medium

What does this program print?

print(36 / 6 * 2)

Question 5 · hard

Ravi has 5 marbles and Nisha has 9. This program swaps the two counts without a third box. What does it print?

ravi = 5
nisha = 9
ravi = ravi + nisha
nisha = ravi - nisha
ravi = ravi - nisha
print(ravi, nisha)

Printing text and reading error messagesNext: Variables: labelled boxes for values