#separator:tab #html:true #tags:python-decisions-quiz #columns:Front Back

What type does the value of 5 > 3 have?

  1. int
  2. str
  3. bool

A comparison answers a yes-or-no question, here with True. True and False are truth values, and their type is called bool.

What is the difference between x = 5 and x == 5?

  1. x = 5 gives x the value 5, x == 5 asks whether x is equal to 5.
  2. x = 5 asks whether x is equal to 5, x == 5 gives x the value 5.
  3. There is none, both ways of writing mean the same.

= assigns and so changes x, == compares and gives True or False without changing anything.

"

What does print(""Yes"" == ""yes"") print?

  1. True
  2. False
  3. An error message, because texts cannot be compared
" "

Texts are only equal if they match character by character, also in upper and lower case. With ""Yes"".lower() == ""yes"" the comparison would give True.

"

What does this program print?

age = 15
student = True
print(age >= 18 or student, not student)
  1. True False
  2. False False
  3. True True
  4. False True

age >= 18 is false, student is true, and for or one true side is enough, so True. not student turns True around and gives False.

Which conditions are true if number = 12? (several are right)

  1. number % 2 == 0
  2. number > 12
  3. 10 < number and number < 20
  4. not number == 12
  5. number in [4, 8, 12]

12 can be divided by 2 without a remainder, lies between 10 and 20 and is in the list. 12 is not greater than itself, and not turns the true comparison number == 12 into False.

"

What does this program print?

temperature = 25

if temperature >= 10:
print(""mild"")
elif temperature >= 20:
print(""warm"")
else:
print(""cold"")
  1. mild
  2. warm
  3. mild and below it warm
  4. cold
"

Python takes the first condition that is true, and 25 is at least 10. It no longer checks the other conditions after that, which is why with ranges the check with the highest value belongs at the top.

"

What does this program print?

answer = ""no""

if answer == ""yes"" or ""y"":
print(""Agreed."")
else:
print(""Declined."")
  1. Agreed.
  2. Declined.
  3. An error message
" "

Python reads the condition as (answer == ""yes"") or ""y"". To the right of the or there is no comparison but the text ""y"", and a text that is not empty counts as true. Correct would be answer == ""yes"" or answer == ""y"" or answer in [""yes"", ""y""].

" "

What does this program print?

def size(number):
if number > 10:
return ""large""
if number > 5:
return ""medium""
return ""small""


print(size(8), size(20))
  1. medium large
  2. medium medium
  3. small large
  4. large medium
" "

8 is not greater than 10 but greater than 5, so size(8) gives the text ""medium"". At 20 the first condition is true, and return ends the function at once with ""large"".

"