Docsity

Python Conditionals and Loops: A Comprehensive Study Guide, Exams of Business Administration

Toggle sidebar
bg1
TechSmart Python Unit 2 WITH 100%
VERIFIED SOLUTIONS 2025/2026
STUDY GUIDE
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")
if y == 2:
print("y is 2")
elif x == w:
print("X is w")
elif x == 5:
print("X is 5")
Remember that a conditional starts with an if-clause.
Which of the following is not a type of conditional clause?
if, elif, then, or else
then
What data type can only be represented as Yes or No and True or False?
boolean
Example of a boolean expression
a == b:
The three basic boolean operators are:
pf3
pf4
pf5

Partial preview of the text

Download Python Conditionals and Loops: A Comprehensive Study Guide and more Exams Business Administration in PDF only on Docsity!

TechSmart Python Unit 2 WITH 100%

VERIFIED SOLUTIONS 2025/

STUDY GUIDE

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") if y == 2: print("y is 2") elif x == w: print("X is w") elif x == 5: print("X is 5") Remember that a conditional starts with an if-clause. Which of the following is not a type of conditional clause? if, elif, then, or else then What data type can only be represented as Yes or No and True or False? boolean Example of a boolean expression a == b: The three basic boolean operators are:

AND, OR, and NOT. How many times will the following code print the statement "Print me"? x = 0 while x < 1000: print("Print me") x += 100 10 Identify the if-clause in the following code. if x < y: print("x is smaller") print("y is bigger") if x < y: Identify the condition in the following code. if x < y: print("x is smaller") print("y is bigger") x < y What happens if the condition in a conditional is False? The program skips the then-block In the following code, the then-block will never execute. Why? if 100 < 10: print("We executed!") print("Congratulations!") print("The program finished.") The condition will always be false. 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:

Tell whether the result of this boolean expression is True or False. not 0 < 10 False If the word yes prints below, what is the value of the variable x? if x == y: if y == 100: print("yes") else: print("no") 100 Identify the error in the following conditional. if x > 100 print("x is greater than 100") if x > 100: *colon was missing What 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 equal What is the maximum number of else-clauses in a single conditional? 1 How 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 condition What is the fewest lines that can be in a then-block? 1 Which logical operator gives the opposite of a boolean value? not Identify 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 weather Identify 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 == y Which 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 y True

True What is the name of the library used in this code? import random x = 0 y = 0 if x == y: print("x and y are equal") elif x == 0: print("x is 0") random If you encounter a error in your code, what is the most likely cause to prevent your code from running? syntax error What symbol is used to separate multiple arguments while using a function call? , or comma What is the most common cause for a runtime error? Not typecasting a variable correctly. How many times will the following code print the statement "Print me"? import random loops = random.randint(1, 200) while loops > 0: loops - = 1 print("Print me") 200 What is one use for a dot operator in Phyton? Call a function from a library What two arguments does the random.randint function require? minimum and maximum If you experience errors in your code, how might you find a logic error? Insert print statements If you experience errors in your code, how might you find a runtime error? Use error messages or print statements If you experience errors in your code, how might you find a syntax error? Look at the error message that pops up