#separator:tab #html:true #tags:python-decisions-quiz #columns:Front Back
What type does the value of 5 > 3 have?
intstrboolboolA 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?
x = 5 gives x the value 5, x == 5 asks whether x is equal to 5.x = 5 asks whether x is equal to 5, x == 5 gives x the value 5.x = 5 gives x the value 5, x == 5 asks whether x is equal to 5.= assigns and so changes x, == compares and gives True or False without changing anything.
What does print(""Yes"" == ""yes"") print?
TrueFalseFalseTexts 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)True FalseFalse FalseTrue TrueFalse TrueTrue Falseage >= 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)
number % 2 == 0number > 1210 < number and number < 20not number == 12number in [4, 8, 12]number % 2 == 010 < number and number < 20number 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"")mildwarmmild and below it warmcoldmildPython 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."")Agreed.Declined.Agreed.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))medium largemedium mediumsmall largelarge mediummedium large8 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"".