What determines which statements belong to the body of an if, for, while, or function definition in Python?
1 Python Syntax and Program Structure Online Quiz Questions
Use this free practice quiz with 20 questions to review 1 Python Syntax and Program Structure, test your knowledge, and prepare for your next test or exam.
True or false: If a user types 27 in response to input(), the returned value is still a string.
- A
True
- B
False
Complete the sentence: When an indented Python block is syntactically required but no action is needed yet, use .
What value does this Python expression produce? (2 + 3) * 4
- A
14
- B
20
- C
24
- D
26
Select all expressions that convert user-entered text to an integer.
- A
int(age_text) - B
age_text + 1 - C
str(age_text) - D
int(input("Age: "))
What exception does Python normally raise when a program uses a name before assigning a value to it?
Complete the sentence: In Python, a one-line comment begins with and continues to the end of the physical line.
True or false: In Python, is is the recommended operator for comparing ordinary values such as two integers.
- A
True
- B
False
What does this statement write, including its ending character? print("A", "B", sep="-", end="!")
- A
A B - B
A-Bfollowed by a newline - C
A-B! - D
A!B!
Select all strings that can be used as ordinary Python names.
- A
student_count - B
2nd_place - C
maximum-speed - D
Total - E
for
What integer value does the Python expression 7 // 2 produce?
A program contains the statement print("Area:", area and reports a syntax error. Explain the cause of the error and write the corrected statement.
A long arithmetic expression should be split across physical lines while remaining one logical line. Which approach is generally clearest in Python?
- A
End each physical line with a semicolon.
- B
Enclose the expression in parentheses.
- C
Indent the second physical line with a tab.
- D
Put a comment at the end of the first physical line.
Which statement correctly distinguishes Python’s is and == operators?
- A
isconverts both values to strings before comparing them. - B
isperforms numeric comparison, while==performs text comparison. - C
ischecks whether a value is truthy, while==checks whether it is false. - D
istests object identity, while==tests value equality.
In label = "Chapter #1", the # character begins a Python comment.
- A
True
- B
False
Which built-in Python function reads one line of user input and returns it as a string?
What happens in Python when total, Total, and TOTAL are used as names?
- A
totalandTotalrefer to the same name, butTOTALis different. - B
total,Total, andTOTALare three different names. - C
Only
TOTALis a valid Python name. - D
Python treats all three names as invalid because they differ only by case.
After width, height = 8, 5 and area = width * height execute, what value is printed by print(area)?
- A
13
- B
40
- C
85
- D
3
What is the value of can_enter after this code executes: colors = ["red", "blue", "green"]; requested = "blue"; is_available = requested in colors; is_guest = False; can_enter = is_available or is_guest?
- A
True
- B
False
- C
blue
- D
None
What integer value is assigned to result by base = 3; exponent = 2; result = base ** exponent?