Chapter 8

Task 1

Variable TypeDescription
boolThis has two possible values, True or False (1 or 0).
listAn ordered sequence of items.
setA group of unordered items that are all different (each is unique).
floatPositive or negative numbers with decimal points.
intPositive or negative whole numbers.
stringEssentially, a piece of text of any kind.

Task 2

The following are my answers to the question on naming variables:

  • A variable holding the age of someone in years: age_years
  • A variable holding a street address: address
  • A variable holding the value True if someone is a member: is_member
  • A variable holding a Date of birth: birth_date/birthday

Task 3

8.3: a.py

number1 = "12"
number2 = "34"

print(number1 + number2)

number3 = int(number1)
number4 = int(number2)

print(number3 + number4)

Output

>>> 1234
>>> 46

Task 4

8.4: int.py

float_num = 2.1
int_num = int(float_num)


print(int_num)

assert float_num != int_num

Output

>>> 2