0% found this document useful (0 votes)
2 views6 pages

2 Python Review

The document contains a series of questions related to Python programming, including single-choice, true/false, and multiple-choice questions, as well as programming tasks. It covers topics such as function definitions, data types, control statements, and string manipulations. Additionally, it includes programming exercises that require generating random integers, checking for prime numbers, and extracting information from ID numbers.

Uploaded by

arthur5523felix
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views6 pages

2 Python Review

The document contains a series of questions related to Python programming, including single-choice, true/false, and multiple-choice questions, as well as programming tasks. It covers topics such as function definitions, data types, control statements, and string manipulations. Additionally, it includes programming exercises that require generating random integers, checking for prime numbers, and extracting information from ID numbers.

Uploaded by

arthur5523felix
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Ⅰ.

Single-choice questions
6. The keyword for defining a function in Python is ( ).
A. for
B. while
C. if
[Link]
7. Given x = [3, 5, 6], after executing the statement [Link](4), the value of x is ( ).
A.[3, 5, 6, 4]
B.[4]
C.[3, 5, 6]
D.4
8. The function used to return the length of string s is ( ).
A. abs(s)
B. len(s)
C. count(s)
D. max(s)
[Link] of the following statements is incorrect ( ).
A. All standard objects except dictionary types can be used for Boolean tests
B. The Boolean value of an empty string is False
C. The Boolean value of an empty list object is False
D. The Boolean value of any numeric object with a value of 0 is False
10. The correct Python statement is ( ).
A. min = x if x < y else y
B. max = x > y ? x : y
C. if (x > y) print x
D. while True : pass
11. How to execute Python source program ().
A. Compile and execute
B. Explanation and execution
C. Direct execution
D. Compile and execute
12. The flow control statement used to terminate the loop early is ( ).
A. pass
B. continue
C. break
D. try
13. Given a list x = [1, 2, 3], after executing the statement [Link](0, 4), the value of x
is ( ).
A.[1,2,3,4]
B.[4,2,3,1]
C.[4,1,2,3]
D.[4,3,2,1]
14. The list comprehension that can generate squares of elements from 0 to 9 is ( ).
A. [x * 2 for x in range(10)]
B. [x * x for x in range(10)]
C. (x * x for x in range(10))
D. {x * x for x in range(10)}
[Link] value of the expression {1, 2, 3} & {3, 4, 5} is ( ).
A.{1, 2}
B.{1,2, 4, 5}
C.{3}
D.{4, 5}
16. Given the list object x = ['11', '2', '3','1'], the value of the expression max(x) is ( ).
A. ' 1'
B.'2'
C. '3'
D.'11'
17. There is a string '10111100', then the result of set('10111100') is ( ).
A. {'1', '0', '1', '1', '1', '1', '0', '0'}
B. {'0', '1'}
C. '10111100'
D. 10111100
18. Given that num = 3.00001284 , the output of running print("{:.3f}".format(num))
is ( ).
A. 3.0
B. 3.000
C. 3.00
D. 3.00001284
19. Given g = lambda x, y=3, z=5: x*y*z, the output of the statement print(g(1, z=2))
is ( ).
A.30
B.6
C.10
D.15
20. In exception handling, statements that need to be executed regardless of whether
an exception occurs are placed under the ( ) branch.
A. try
B. except
C. else
D. finally

Ⅱ. True or False Questions .


1. The Boolean expression '' or 10 evaluates to True . (True )
2. Without importing the standard library math, the statement x = 3 or [Link](9)
can also be executed normally, and the value of x after execution is 3.
(False )
3. Elements in a set are not allowed to be repeated. ( True)
4. Tuples containing lists can be used as dictionary "keys". ( False)
5. When writing code, try to reduce blank lines and spaces to make the code more
compact. ( False)
6. Slicing operations can only be performed on lists, not on tuples and strings. (
False)
7. Strings are Python ordered sequences and support bidirectional indexing like lists
and tuples. (True )
8. The Python operator % can not only be used to find the remainder, but also to
format strings. (True )
9. When defining a function, even if the function does not need to receive any
parameters, you must retain a pair of empty parentheses to indicate that this is a
function. (True )
10. range(5) can get the integer sequence of 1, 2, 3, 4, 5. (False )
11. Python source program files are text files. (True )
12. If it is only used to control the number of loops, then for i in range(20) and for i in
range(20, 40) are equivalent . (True)
13. The elements in the set are unordered . (True)
14. The "keys" in the dictionary are not allowed to be repeated, but the "values" can
be repeated. ( True)
15. You can only access elements in a list through slicing, and you cannot use slicing
to modify elements in a list. (False )

Ⅲ. Multiple-choice questions
1. The basic properties of objects in Python are (ABC ).
A. Type
B. Value
C. Identification
D. Name
2. Execute the statement num = input(), the user enters the integer 3, the correct
answer is (AC ).
A. The value of num is the string '3'
B. The value of num is the integer 3
C. If num is used in numerical calculations, you can use int(num) to convert the string
'3' into the integer 3.
D. If num is involved in numerical calculations, you can use float(num) to convert the
resulting string '3' into the integer 3
3. The main differences between tuples and lists are (ACD ).
A. Tuples are immutable data types, lists are mutable data types
B. Tuples can be empty, but lists cannot be empty
C. The delimiters of tuples are parentheses, and the delimiters of lists are square
brackets.
D. The built-in methods of tuples are only count() and index(), while lists have more
built-in methods.
4. The expression for determining whether an integer is in the interval [85, 100]
(square brackets indicate a closed interval) is ( BD).
A. 85 ≤ num ≤ 100
B. 85 <= num <= 100
C. num ≥ 85 and num ≤ 100
D. num >= 85 and num <= 100
5. A set is a data type that places elements in {} and separates them with commas.
Regarding sets, the correct option below is ( ABD).
A. The elements in the set are unordered
B. There are no duplicate elements in the set
C. The elements in the collection are immutable data types
D. Data in a mutable collection can be added and deleted
6. " +" can be used to concatenate multiple strings into one. The correct ones are (
ABD).
A. 'Welcome' + " 2021 "
B. "Welcome" + '2021'
C. "Welcome" +2021
D. " Welcome "+str(2021)
7. s = "Hello world!" , the following program statements and comments are correct
(ACD ).
A. print(s[3:5]) # Output lo
B. print(s[5:3]) # Output an empty string
C. print(s[::-1]) # Output!dlrow olleH
D. print(s[-1::-1]) # Output!dlrow olleH
8. Regarding the return value of the function, the following statements are correct
(ABCD ).
A. The keyword for a function to return a value is return
B. When a function has no return value statement, the return value is None
C. Functions can have no return value and directly output processing results or plots
D. A function can have multiple return value statements, but only one of them can be
executed
9. Which of the following data can be converted into integers using the int() function (
AD).
A. print(int(3.14))
B. print(int(' '))
C. print(int('3'))
D. print(int('3.14'))
10. If year = 2021 , the following statements can correctly output "2021" (BCD ).
A. print(year + "年")
B. print(str(year) + 'year')
C. print(f'{year}年')
D. print('{}year'.format(year))
11. A tuple is a group of data placed in parentheses, with the data separated by
commas. The following options have data of tuple type (ACD ) .
A. ()
B. (1)
C. 1,
D. (1,2,3,4)
12. Regarding the break keyword, the correct statement is (AC ) .
A. Must be placed in a loop statement
B. Must be placed after the conditional statement
C. A break can only jump out of the loop closest to it
D. A break can jump out of multiple loops
13. The statements that can convert the binary number 11111010 into a decimal
integer are ( BCD) .
A. print(int('0B11111010', base=2))
B. print(int('11111010', base=2))
C. print(int('0b11111010', 2))
D. print(int('11111010', 2))
14. Regarding anonymous functions, the following statements are correct ( ABCD) .
A. An anonymous function is a function without a name
B. Anonymous functions can be used as function parameters
C. Applying anonymous functions can make the code more concise
D. Excessive use of anonymous functions may make the program less readable.
15. List is one of the most widely used and flexible data types in Python. The correct
description of list elements is (ABCD ) .
A. List elements can all be integers
B. List elements can be of different types
C. List elements can still be lists
D. List elements can be added and deleted

Ⅳ. Write the result question


1. The running result of the following program is ( ) .
s=0
for i in range(1,101):
s += i
else:
print(1)
Answer:1
2. The running result of the following program is ( ) .
def Join(List, sep=None):
return (sep or ',').join(List)
print(Join(['e', 'f', 'g'],))
print(Join(['e', 'f', 'g'],':'))
Answer:
e,f,g
e:f:g
3. The execution result of the following program is ( ).
list1=[1,2]
list2=list1[::]
list1[0]=3
print(list1,list2)
Answer:
[3, 2] [1, 2]

4. When input 1 0 , the execution result of the following code is ( ).


n = int(input())
result = 0
for i in range(1, n):
if i % 2 == 1:
result = result + i
print(result)
Answer:
0

Ⅴ. Programming questions (Four of them have two exams)


1. Write a program to randomly generate 50 integers between [1, 20] and then count
the frequency of occurrence of each integer.

2. Write a function to determine whether a number is prime. If it is, it returns the


string YES ; otherwise, it returns the string NO .

3. The 7th to 10th digits of the 18-digit ID number are the year of birth (4 digits), the
11th to 12th digits are the month of birth, the 13th to 14th digits represent the date of
birth, and the 17th digit represents the gender, with odd numbers representing males
and even numbers representing females. Write a program to output the user's date of
birth and gender when the user enters a valid ID number.

4. Write a program . When the user inputs a positive integer, output all prime numbers
not greater than the number in one line, with each number separated by a space.

You might also like