Xi'an Petroleum University Python final review

Python final review

 

1. Multiple Choice Questions

1. The Python language belongs to (C)

A. Machine language B. Assembly language C. High-level language D. None of the above

2. In the Python interpreter environment, the special variable used to represent the result of the last operation is (B)

A.  :     B.  _     C.  >    D.#

3. In order to assign the initial value 10 to the integer variables x, y, and z, the following correct Python assignment statement is (C)

A. xyz=10     B. x=10y=10z=10    C. x=y=z=10    D. x=10,y=10,z=10

4. In Python expressions, you can use (A) to control the priority of operations

A. Parentheses () B. Square brackets [] C. Braces {} D. Angle brackets <>

 

5. The following if statement counts the number of people who meet the conditions of "gender (gender) is male, professional title (rank) is associate professor, and age (age) is less than 40 years old". The correct statement is (B)

A. if(gender== "Male" or age < 40 and rank == "Associate Professor"): n+=1

B. if(gender =="Male" and age<40 and rank== "Associate Professor"): n+=1

C. if (gender =="Male" and age<40 or rank== "Associate Professor"): n+=1

D. if(gender =="male" or age<40 or rank=="associate professor"): n+=1

6. The following if statement counts the number of "boys with excellent scores and boys who fail". The correct statement is (C)

A. if(gender=="男" and score<60 or score>= 90): n+=1

B. if (gender=="男" and score<60 and score>= 90): n+=1

C. if (gender =="男" and (score<60 or score> =90)): n+=1

D. if(gender =="男" or score<60 or score>=90): n+=1

7. In the following for statement structure, the one that cannot complete the accumulation function of 1~10 is (A)

A. for i in range(10,0): total += i

B. for i in range(1,11): total += i

C. for i in range(10,0,-1): total+=i

D. for i in (10,9,8,7,6,5,4,3,2,1): total += i

8. The output of the Python statement print(type(1/2)) is (C)

A. <class 'int'>    B. <class 'number'>    C. <class 'float>    D. <class 'double'>

9. The result of the Python statement print(chr(65) is (D)

A.65      B.6      C. 5      D. A

10. Regarding Python strings, which of the following statements is wrong (B)

A. A character is a string of length 1

B. The string ends with \0 to mark the end of the string

C. Both single quotes and double quotes can be used to create strings

D. Special characters such as newline and carriage return can be included in the triple-quoted string

11. The output of the Python statement nums = set([1,2,2,3,3,3,4]); print(len(nums)) is (C)

A.1     B.2      C.4     D.7

12. The Python statement d={1:'a',2:b',3:'c'}; the result of print(len(d)) is (C)

A.0     B.1      C.3     D.6

13. Assuming that the dictionary d= {'1':'male', '2':'female'} in the Python program, if d[3] is used in the statement, the interpreter will throw a (C) error message

A. NameError     B. IndexError     C. KeyError     D. TypeError

14. In Python, if def fl(p, **p2): print(type(p2)), the program running result of fl(1, a=2) is (C)

A. <class 'int '>     B. <class 'type'>      C. <class 'dict'>     D. <class 'list'>

2. Fill in the blanks

1. The Python language is an interpreted, object-oriented computer programming language.

2. To close the Python interpreter, use the quit() command or the shortcut key Ctrl+Z

3. Python uses the symbol \ ( backslash ) to translate characters.

4. The value of Python expression 4.5/2 is 2.25 ; the value of Python expression 4.5//2 is 2.0 ; the value of Python expression 5%2 is 1.0

5. The value of the Python expression 12/4-2+5*8/4%5/2 is 1.0

6. Python infinite loop while True: The break statement can be used in the loop body to exit the loop

7.Python's four built-in numerical types are integer type (int), Boolean type (bool), floating point type (float), complex type (complex)

8. The result of the Python statement s= [1, 2, 3, 4]; s.append([5,6]); print(len(s)) is 5

9. The result of the Python statement print(1,2,3,4,5,sep='-',end='!') is 1-2-3-4-5!

10. In the Python language, use sys.stdin , sys.stdout , and sys.stderr in the sys module to view the corresponding standard input, standard output, and standard error stream file objects.

11. Custom exception classes are generally inherited from Exception or its subclasses.

12. Variables can be roughly divided into global variables, local variables and type member variables according to their scope

program fill in the blank

  1. def  getValue(b,r,n)

return v

  1. max_v=b

  for x in c

  max_v =x

  return max_v

  if x<min_v

programming

if a>0 and b>0 and c>0:

  if a+b>0 and a+c>0and b+c>0

    length=(a+b+c)

    h=length/2

    s=math.sqrt(h*(h-a)*(h-b)*(h-c))

  else:

     print('Cannot form a triangle')

else:

print(‘Error Data’)

 

Guess you like

Origin blog.csdn.net/shaozheng0503/article/details/131457562