Python Arena
Step 2 of 5

Numbers and strings

Variables can hold numbers as well as strings. A whole number, such as 7, -40 or 1000000, is called an integer. You write it without quotes:

year = 2026
print(year)
print(year + 1)
Output
2026
2027

"25" is not 25

With quotes, "25" is a string: two characters that happen to be digits. A locker number and a door code may look alike when printed, but Python treats them differently:

lockers = 25
door_code = "25"
print(lockers)
print(door_code)
print(lockers + lockers)
print(door_code + door_code)
Output
25
25
50
2525

For numbers, + adds. For strings, it joins. What an operator does depends on the type of the values it works on: whether they are integers, strings or something else. Python's short name for the integer type is int, and for the string type it's str.

A look in the interpreter

Python also has an interactive interpreter: you type one line after its >>> prompt, and Python runs it and shows the value right away. It shows a string with its quotes, so you can tell the string '34' from the number 34:

In the Python interpreter
>>> 3 + 4
7
>>> "3" + "4"
'34'

Not every operation works for every type

Taking a number away from a string makes no sense, and Python says so:

width = "12"
print(width - 2)
Python stops with
Traceback (most recent call last):
  File "main.py", line 2, in <module>
    print(width - 2)
          ~~~~~~^~~
TypeError: unsupported operand type(s) for -: 'str' and 'int'

A TypeError means that an operation got values of a type it can't work with. The last line says that - doesn't work on a str and an int (the values an operator works on are its operands). The ~ and ^ marks show the calculation that failed. The fix here is to drop the quotes, so that width holds a number.

Keep in mind that what input gives you is always a string, even when the user types digits. The next module shows how to turn it into a number.

Your task

Challenge 1 of 3

What does this program print? Type each line it prints.

Challenge 2

The program should print the number of fruits in the basket, 12, but it prints 57. Fix it.

12

Challenge 3

At the zoo, a ticket costs 12 for an adult and 7 for a child. The variables hold the number of adults and children in a family. Add two lines that print the number of tickets and then the total price, both calculated from the variables:

5
50