Python Programming Examination Paper
Test duration: 100 minutes
Department: Major: Class:
Name: Student ID: Email:
Teacher: [Link] Email: gjn9868@[Link]
Question Part I Part II Part III Total Score
Score 60 20 20 100
Score
Part I: Single-choice questions (30 questions, 60 points)
[Link] reflects the logical relationship between statements through ( ).(2.0)
A. {}
B. ()
C. Indentation
D. Automatic recognition
[Link] literals in Python must be enclosed in ( ).(2.0)
A. ()
B. ‘ ’
C. “ ”
D. ‘ ’ or “ ”
[Link] symbol representing the start of a comment in Python is ( ).(2.0)
A. &
B. *
C. $
D. #
[Link] operator for integer division in Python is ( ).(2.0)
A. //
B. %
C. **
D. /
[Link] of the following built-in functions can be used to convert an integer to a float?(2.0)
A. int_to_float()
B. float()
C. convert()
D. int()
6.( ) refers to a numerical name that remains unchanged during program execution.(2.0)
A. Named text
B. Named constant
C. Variable signature
D. Keyword
7. The value of a ( ) expression is either True or False.(2.0)
A. Binary
B. Selection
C. Unconditional
D. Boolean
[Link], or, and not are all ( ) operators.(2.0)
A. Relational
B. Logical
C. Arithmetic
D. Conditional
[Link] symbol > is a ( ) operator.(2.0)
A. Relational
B. Logical
C. Arithmetic
D. Conditional
10.( ) structure tests a condition and chooses one execution path when the condition is true and
another when it is false.(2.0)
A. if
B. Single-branch selection
C. Double-branch selection
D. Sequential
11.A double-branch selection structure can be written using a ( ) statement.(2.0)
A. if
B. if-then
C. if-else
D. if-call
12.A compound Boolean expression created with the ( ) operator is true only if both
sub-expressions are true.(2.0)
A. and
B. or
C. not
D. All of the above
13.A compound Boolean expression created with the ( ) operator is true if at least one of the
sub-expressions is true.(2.0)
A. and
B. or
C. not
D. All of the above
[Link] ( ) operator takes a Boolean expression as an operand and flips its logical value.(2.0)
A. and
B. or
C. not
D. All of the above
[Link] of the following built-in functions is used to read input typed from the keyboard?(2.0)
A. input()
B. get()
C. print()
D. read()
[Link] operator for calculating powers is ( ).(2.0)
A. *
B. %
C. **
D. //
17.A loop controlled by ( ) uses a true/false condition to control the number of repetitions.(2.0)
A. Boolean
B. Conditional
C. Decision
D. Count
18.A loop controlled by ( ) repeats a specified number of times.(2.0)
A. Boolean
B. Conditional
C. Decision
D. Count
[Link] repetition of a loop is called an ( ).(2.0)
A. Cycle
B. Rotation
C. Circle
D. Iteration
[Link] while loop is a ( ) type of loop.(2.0)
A. Pre-test
B. No-test
C. Pre-review
D. Post-iteration
21.A ( ) loop cannot stop until the program is interrupted by the system.(2.0)
A. Uncertain
B. Endless
C. Infinite
D. Eternal
[Link] is the role of break?(2.0)
A. Jumps out of the current block based on indentation.
B. Jumps out of all blocks except function indentation.
C. Jumps out of the current for/while loop.
D. Jumps out of all for/while loops.
[Link] part of a program that uses a function is called the ( ).(2.0)
A. User
B. Caller
C. Callee
D. Statement
[Link] beginning of a Python function definition is ( ).(2.0)
A. def
B. define
C. fun
D. function
25.A function can use a ( ) statement to return a value to the caller.(2.0)
A. print
B. return
C. assignment
D. back
[Link] of the following statements about Python functions is correct?(2.0)
A. Reserved words can be used as function names.
B. When calling a function with default parameter values, you cannot pass any value to the
default parameters; you must use the defaults.
C. Variables defined inside a function cannot be accessed by the caller.
D. Each function must have at least one return statement.
[Link] of the following statements about Python functions is incorrect?(2.0)
A. Function definitions do not have to be placed before function calls.
B. When there is a main function in the code, the program will start executing from main.
C. Functions can have no return value.
D. Variables defined inside a function cannot be accessed outside the function.
28. To make the program run normally and output "hi there", which option should be selected?
(2.0)
first = "hi"
second = ( )
total = first + second
print(total)
A. there
B. " there"
C. str(there)
D. 'there'
[Link] option can make the code output 8?(2.0)
x=4
()
print(x)
A. x = x * 2.0
B. x -= x
C. x += x
D. x = x ** 2
[Link] you want the statement print('/usr', 'share', 'doc') to output /usr/share/doc, which
parameter should be set in the print function?(2.0)
A. sep = '/'
B. end = '/'
C. file = '/'
D. flush = '/'
Part II: True/false questions(10 questions, 20 points)
[Link] names allow spaces inside. ( )(2.0) False
[Link] first character of a variable name cannot be a number. ( )(2.0) True
33.A selection structure can be nested within another selection structure. ( )(2.0) True
Answer: True
[Link] input refers only to user input from the keyboard. ( )(2.0) False
[Link] output refers only to display on the monitor. ( )(2.0) False
36.A condition-controlled loop always repeats a specified number of times. ( )(2.0) false
[Link] while loop is a pre-test loop. ( )(2.0) True
[Link] a nested loop, each iteration of the outer loop completes all iterations of the inner loop. ( ) True
(2.0)
[Link] calculate the total number of iterations of a nested loop, you can add the number of
False
iterations of each layer of the loop. ( )(2.0)
[Link] a function is the same as defining a function. ( )(2.0) False
Part III: Programming questions (2 questions, 20 points)
[Link] list a = [1,3,4,7,8,10] and list b = [0,2,3,4,5,8,9], insert elements from list a into list b
and keep list b sorted.(10.0)
a = [1, 3, 4, 7, 8, 10]
b = [0, 2, 3, 4, 5, 8, 9]
[Link](a) # Add all elements from a to b
[Link]() # Sort b
print(b)
[Link] a number guessing game where your program randomly generates an integer between 1
and 50. Let the user input their guess, provide hints ("too big", "too small", or "correct"), and
continue guessing until the user guesses correctly.(10.0)
Hint: The following code can generate a random integer between 1 and 50:
import random import random
num = [Link](1,50) def guessing_game():
num = [Link](1, 50) # Random number between 1 and 50
guess = None
print("Guess the number between 1 and 50.")
while guess != num:
try:
guess = int(input("Enter your guess: "))
if guess < 1 or guess > 50:
print("Please enter a number within the range 1 to 50.")
continue
if guess > num:
print("Too big!")
elif guess < num:
print("Too small!")
else:
print("Correct! You guessed the number.")
except ValueError:
print("Invalid input. Please enter an integer.")
if __name__ == "__main__":
guessing_game()