TechSmart Python Unit 2; 2.1 - 2.3 ONLY

In the following code, identify the conditional that includes the elif-clause.

if x == 1:
print("X is 1")
if y == 2:
print("y is 2")
elif x == w:
print("X is w")
elif x == 5:
print("X is 5")
if x < 53:
print("x is less than 53")
Click the card to flip 👆
1 / 40
Terms in this set (40)
Add a symbol to the conditional so it is formatted correctly. x = 10 y = 5 if x > y print("x is bigger than y")add a colon after if x > y. Should be written if x > y:In the following code, identify the print statement that will never be printed. if x > y: print("Case 1") if x < y: print("Case 2") if x == y: print("Case 3") else: print("Case 4")print("Case 4")What is the maximum number of elif clauses you can have in a conditional?UnlimitedWhat is the maximum number of else clauses you can have in a conditional?1Highlight all the clauses in the conditional below. if money > 100: print("Wow!") elif money > 50: print("Not bad!") elif money > 10: print("You got something!") else: print("You need some cash!")if money > 100: elif money > 50: elif money > 10: else:Which logical operator is only True if all parts are True?andTell whether the result of this boolean expression is True or False. 0 < 10 and 100 > 10TrueTell whether the result of this boolean expression is True or False. 0 < 10 or 100 < 10TrueTell whether the result of this boolean expression is True or False. not 0 < 10FalseIf the word yes prints below, what is the value of the variable x? if x == y: if y == 100: print("yes") else: print("no")100Identify the error in the following conditional. if x > 100 print("x is greater than 100")if x > 100: *colon was missingWhat will print when this code executes? x = 0 y = 0 if x == y: print("x and y are equal") if x == 0: print("x is 0")x and y are equal, x is 0 (on separate lines)What will print when this code executes? x = 0 y = 0 if x == y: print("x and y are equal") elif x == 0: print("x is 0")x and y are equalWhat is the maximum number of else-clauses in a single conditional?1How would you fix the comparison operator in the following conditional so the print statement is accurate. if people > 50: print("There are fewer than 50 people.")if people < 50:Why will the code below cause an error? if x == 100: print("100") elif: print("x is not 100")elif must have a conditionWhat is the fewest lines that can be in a then-block?1Which logical operator gives the opposite of a boolean value?notIdentify the expressions in the following code that produce a boolean value. There are 2. weather = sleet or snow outside = not weather print("I should go outside: " + str(outside))sleet or snow not weatherIdentify the expression in the following code that produces a boolean value. print("Check if the values are the same: ") same = x == y print(same)x == yWhich of the following single clauses could replace both the nested clauses while keeping the same meaning? if x == y: if x == 0: print("y is 0")if x == y and x == 0:What is the value inside the variable z after this code executes? x = True y = True z = x or yTrueWhich of these is NOT a benefit of using loops? Loops make code run faster. We don't have to write the same code over and over. We can repeat without knowing how many times we need to. Loops can perform the same code again and again.Loops make code run faster.In the code below, identify the while-clause. x = 1 while x <= 10: print(x) x += 1while x <= 10:Why is this not a valid loop? x = 10 while x > 0: print(x) x -= 1The loop-block isn't indented.Change one symbol in the loop-block to stop this from being an infinite loop. x = 50 while x < 100: x -= 1x += 1In the code below, identify the condition. x = 1 while x <= 10: print(x) x += 1x <= 10Will the following boolean expression return True or False? 300 == 3000 or 300 > 0TrueWill the following boolean expression return True or False? 500 == 5000 and 500 > 0FalseWill the following boolean expression return True or False? 100 == 1000 or 100 > 0True