if/elif/else conditionals Flashcards
True or false?
Inside an if/elif/else code block, if an expression is evaluated as True, then the code indented below the if statement will be executed. Otherwise, Python goes further and evaluates the elif or else statements, if any.
True
True or false?
In Python, an if/elif/else code block may contain maximum two else clauses, as long as they are the last clauses in the block, after any if and elif clauses.
False. Only 1 else block can be used
True or false?
The else clause gets executed if the expression in the if clause is evaluated as False and the expression in the elif clause is evaluated as True.
False. The elif clause was True.
True or false?
You may have as many elif clauses as you need inside an if/elif/else code block.
True.
True or false?
Every if clause must have at least one elif or else clause following it.
False.
What is the result of the code below?
mystring = “Solving Python quizzes is awesome. Can I have more, please?”
if mystring.endswith(“?”) and len(mystring) != 60:
print(“Great job!”)
Great job!
What is the result of the code below?
mystring = “Solving Python quizzes is awesome. Can I have more, please?”
if “ “ not in mystring or mystring.find(“zz”) <= 15:
print(“Great job!”)
No output is returned.
What is the result of the code below?
mystring = “Solving Python quizzes is awesome. Can I have more, please?”
if mystring[5:8].endswith(“ “) or (mystring.count(“,”) > mystring.index(“o”)):
print(“Great job!”)
else:
print(“Great job again!”)
Great job!
What is the result of the code below?
mystring = “Solving Python quizzes is awesome. Can I have more, please?”
if mystring[5:8].startswith(“i”) and (mystring[::2][2] == “i”):
print(“Great job!”)
elif “a” in mystring[-7:-4] or mystring[-2:] == “e?”:
print(“Great job once again!”)
else:
print(“Great job again!”)
Great job once again!
What is the result of the code below?
if mystring[5:8].startswith(“i”) and (mystring[::2][2] == “i”):
print(“Great job!”)
elif “a” in mystring[-7:-4] and mystring[-2:] == “e?”:
print(“Great job once again!”)
else:
print(“Great job again!”)
Great job again!
What is the result of the code below?
mynum = 2500
if mynum % 25 == 0 and mynum // 25 == 10 ** 2:
print(“Awesome!”)
Awesome!
What is the result of the code below?
mynum = 2500
if (100 - 5 ** 2 * 2 ** 2):
print(“Awesome!”)
elif mynum / (100 - 5 ** 2 / 5 * 2 + 10) < 29:
print(“Amazing!”)
Amazing!
What is the result of the code below?
mynum = 2500
if mynum % pow(5, 2) < 100: print("Awesome!") elif abs(10 % 2 - mynum) < 2019: print("Amazing!") elif type(mynum / 50) is not int: print("Cool!") else: print("Whatever!")
Awesome!
What is the result of the code below?
mynum = 2500
if mynum % abs(-mynum // 100) > 100: print("Awesome!") elif max(mynum % 250, mynum % 500) == 0: print("Amazing!") elif type(mynum / 50) is not int: print("Cool!") else: print("Whatever!")
Amazing!
What is the result of the code below?
mylist = [10, 50, 78.13, 99.9, “Python”, “Java”, “SQL”]
if max(mylist) < 100: print("Awesome!")
Error