How does Python normally delimit the block of statements controlled by a compound-statement header such as an if statement?
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.
Which token starts a Python comment when it appears outside a string literal?
- A
// - B
/* - C
# - D
--
Which statement correctly reads a quantity that will be used as an integer in later arithmetic?
- A
quantity = int(input("Quantity: ")) - B
quantity = input("Quantity: ") - C
quantity = str(input("Quantity: ")) - D
quantity = print(input("Quantity: "))
Which grouping characters allow a Python statement to continue across multiple physical lines? Select all correct answers.
- A
Parentheses
- B
Brackets
- C
Braces
- D
Semicolons
- E
Colons
Which two statements accurately describe Python’s Boolean operators? Select all correct answers.
- A
andis true when both operands are true. - B
oris true when at least one operand is true. - C
notis true only when both operands are true. - D
andalways returns the Boolean objectTrueorFalse.
True or false: In a module containing if __name__ == "__main__": main(), the call to main() normally runs when another module imports it.
- A
True
- B
False
True or false: Python treats count and Count as different names.
- A
True
- B
False
When a Python file is executed directly as a script, what exact string value does its special variable __name__ have?
What value does the Python expression 7 / 2 produce?
A string literal placed as the first statement in a module, function, or class is called a .
In Python, a compound-statement header such as an if header ends with a before its indented suite.
Explain how name = supplied_name or "Guest" works for both truthy and falsy values of supplied_name. Include what short-circuit evaluation contributes and whether the result must be a Boolean.
What is the main purpose of placing main() inside if __name__ == "__main__":?
- A
It prevents all top-level statements from executing.
- B
It runs
main()when the file is executed directly but not when imported. - C
It makes every function execute immediately when the module loads.
- D
It converts the module into a package.
True or false: A comment beginning with # is ignored by Python during parsing when the # appears outside a string literal.
- A
True
- B
False
What is the name of Python's // operator?
In the pattern if __name__ == "__main__":, what special variable is being tested?
A program needs to add 3 to a whole-number quantity entered by the user. Which expression obtains that quantity as an integer?
- A
int(input("Quantity: "))
- B
input("Quantity: ")
- C
str(input("Quantity: "))
- D
float(input("Quantity: "))
Which punctuation mark must be added to make this Python structure syntactically complete?
if score > 90
print("Excellent")
- A
A semicolon
- B
A comma
- C
A colon
- D
A period
Which result is correct for this Python code?
if logged_in: print("Welcome") print("Dashboard")
- A
The statements use inconsistent indentation within the
ifsuite, producing anIndentationError. - B
The statements are at the same indentation level as the
ifheader, which is required for the suite. - C
The statements are separated with semicolons, which makes the block invalid.
- D
The
ifheader does not end with a colon, so Python cannot begin the suite.
A Python file defines a main() function and ends with if __name__ == "__main__": followed by main(). What happens when another module imports this file?
- A
The guard prevents
main()from running during import. - B
The guard converts the module into a class.
- C
The guard makes every top-level statement execute twice.
- D
The guard prevents the module from being imported.
Related study packs and tools
2 Digital Logic
A 14-question medium-difficulty quiz on Boolean algebra, logic gates, truth tables, and combinational circuits.
03 — Python Programming Fundamentals
A focused set of flashcards covering Python variables, data types, expressions, control flow, functions, input, output, and common programming practices.
04 Conditionals and Boolean Logic
Learn how Boolean expressions, logical operators, and conditional structures let programs make reliable decisions, including how to handle boundaries, branch order, and testing.
6 Computer Memory
Learn how computer memory stores and addresses information, how RAM and ROM differ, and how caches and the memory hierarchy balance speed, capacity, and cost.
07 Trees and Binary Search Trees
A progressive guide to tree structure, binary-tree traversals, binary search tree operations, deletion, balancing, and the way tree height determines time and space costs.
12 — Foundations Capstone: Integrating Computer Science
A practical guide to integrating problem definition, data representation, modular programming, algorithms, complexity analysis, testing, correctness, and ethical evaluation into a responsible computer science capstone.
Interrupts
Reviews how interrupts support event handling and multitasking, and how Linux system calls use the RISC-V `ecall` instruction and register conventions.
OS Processes
This quiz covers process management, context switching and scheduling, multitasking, traps and interrupts, and RISC-V privilege transitions.
Systemcalls
A quiz on operating-system system calls, including privileged-operation requests, process creation and execution with fork, exec, and waitpid, and signal handling.