if/elif/else conditionals Flashcards

1
Q

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.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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.

A

False. Only 1 else block can be used

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

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.

A

False. The elif clause was True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

True or false?

You may have as many elif clauses as you need inside an if/elif/else code block.

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

True or false?

Every if clause must have at least one elif or else clause following it.

A

False.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

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!”)

A

Great job!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

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!”)

A

No output is returned.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

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!”)

A

Great job!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

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!”)

A

Great job once again!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

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!”)

A

Great job again!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the result of the code below?

mynum = 2500

if mynum % 25 == 0 and mynum // 25 == 10 ** 2:
print(“Awesome!”)

A

Awesome!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

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!”)

A

Amazing!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

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!")
A

Awesome!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

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!")
A

Amazing!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the result of the code below?

mylist = [10, 50, 78.13, 99.9, “Python”, “Java”, “SQL”]

if max(mylist) < 100:
    print("Awesome!")
A

Error

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the result of the code below?

mylist = [10, 50, 78.13, 99.9, “Python”, “Java”, “SQL”]

if len(mylist) % 7 >= mylist.index(50):
    print("Awesome!")
else:
    print("Magic!")
A

Magic!

17
Q

What is the result of the code below?

mylist = [10, 50, 78.13, 99.9, “Python”, “Java”, “SQL”]

if mylist[-3][-3] != “h” and len(mylist) == 8:
print(“Awesome!”)
else:
print(“Magic!”)

A

Magic!

18
Q

What is the result of the code below?

mylist = [10, 50, 78.13, 99.9, “Python”, “Java”, “SQL”]

if type(mylist[-3]) is str and type(mylist[3]) is not float:
    print("Awesome!")
else:
    print("Magic!")
A

Magic!

19
Q

What is the result of the code below?

mylist = [10, 50, 78.13, 99.9, “Python”, “Java”, “SQL”]

if sorted(mylist[:4], reverse = True)[1] > 50 and mylist[::-1][0].startswith("J"):
    print("Awesome!")
else:
    print("Magic!")
A

Magic!

20
Q

What is the result of the code below?

mylist = [10, 50, 78.13, 99.9, “Python”, “Java”, “SQL”]

if mylist[2:4] == mylist[-5:-2]:
    print("Awesome!")
elif mylist[::2][2][0] > mylist[::3][2][-1]:
    print("Super!")    
else:
    print("Magic!")
A

Super!

21
Q

What is the result of the code below?

mylist = [10, 50, 78.13, 99.9, “Python”, “Java”, “SQL”]

if len(mylist[:5]) == 10 % 6 - 1:
    print("Awesome!")
elif len(mylist[::-1][:3]) == 10 % 7:
    print("Super!")    
else:
    print("Magic!")
A

Super!

22
Q

What is the result of the code below?

mydict = {1: “BTC”, 2: “ETH”, 3: “XRP”, 4: “LTC”, 5: “EOS”, 6: “ADA”, 7: “XLM”}

if len(mydict.keys()) == list(mydict.items())[-1][0]:
    print("Awesome!")
elif len(mydict.values()) == list(mydict.items())[-1][0]:
    print("Super!")    
else:
    print("Magic!")
A

Awesome!

23
Q

What is the result of the code below?

mydict = {1: “BTC”, 2: “ETH”, 3: “XRP”, 4: “LTC”, 5: “EOS”, 6: “ADA”, 7: “XLM”}

if mydict.get(4).endswith(“c”) and mydict.get(6).count(“A”) >= 2:
print(“Awesome!”)
else:
print(“Magic!”)

A

Magic!

24
Q

What is the result of the code below?

mydict = {1: “BTC”, 2: “ETH”, 3: “XRP”, 4: “LTC”, 5: “EOS”, 6: “ADA”, 7: “XLM”}

if type(list(mydict.items())[2]) != list:
    print("Awesome!")
elif type(list(mydict.items())[0]) == tuple:
    print("Super!")
else:
    print("Magic!")
A

Awesome!