College python question bank and answer analysis, college python programming question bank

This article will talk about the university python question bank and answer analysis, as well as python final programming questions and answers. I hope it will be helpful to you. Don’t forget to bookmark this site.

 

Publication time: 2020-07-07

1. Fill in the blanks (15 points)

  1. Use the print() function to output multiple strings 'How', 'are ', and 'you' together. The statement is __  Print("How", "are", "you")  _  PYTHON library "IMITATION" .
  2. Use the input() function to output the "Please enter your name:" statement and obtain the data from the keyboard. The statement is _  input("Please enter your name:")  _.
  3. __List  _____ , ___ Tuple _ ___ are Python’s ordered data types;  __Set _____ , __ Dictionary _ ____ are unordered data types.
  4. testword=’hello, Python!’,testword[-4]= _ ____ 。 testword[2:5]= _ llo _
  5. Python's built-in function _  count __ ____ can return the number of elements in a list, tuple, dictionary, set, string, and range object.
  6. Python's built-in function _ len ______ _ can return the number of all elements in a list, tuple, dictionary, set, string, and range object.
  7. The execution result of the Python statement list(range(1,10,3)) is __ [1,4,7] ___________.
  8. The statement sorted([1, 2, 3], reverse=True) means _ to sort the numbers in the list from large to small, and the result is a list ___.
  9. Use the __break__ statement in a loop to break out of a deep loop.
  10. The expression [x for x in [1,2,3,4,5] if x<3] evaluates to __ [1,2] ____ .
  11. The expression set([1, 1, 2, 3]) evaluates to _ {1,2,3} _____ .
  12. To get the union of two sets A and B, you should use the __ | notation or the union function __ in Python.
  13. When using the import statement to import a function, you can use the ___ as ____ statement to specify an alias for the function.

2. True or False Questions (10 points)

  1. Expression [1,2,3] is the same as expression [2,3,1]. (f)
  2. Python is a cross-platform, open source, and free high-level dynamic programming language. (t)
  3. Python 3.x is fully compatible with Python 2.x. (f)
  4. Python does not allow the use of keywords as variable names, but allows the use of built-in function names as variable names. However, this will change the meaning of the function name, so it is not recommended. (t)
  5. After executing the statement from math import sin, you can directly use the sin() function, such as sin(3). (t)
  6. Python variable names are not case-sensitive, so student and Student are the same variable. (f)
  7. When the variable parameters *args are passed into the function, they are stored in a list. (f)
  8. It is known that x = 3, then after executing the statement x+=6, the memory address of x remains unchanged. (f)
  9. Dictionary queries are not as fast as lists and tuples. (f)
  10. Determine whether the following code segment is legal (f)

>>>number = 5

>>>print(number + ”is my lucky number.”)

3. Multiple choice questions (10 points)

  1. Slicing of list data type elements in Python is very powerful. For the list mylist=[1,2,3,4,5,6,7,8,9], the following operation is correct (B). A. mylist[1:9:0] B. mylist[1:9:2] C. mylist(6:-9:-2) D. mylist[10::]
  2. The operator with the highest precedence is ( C ).

A、is              B、*             C、**               D、+

3. Among the following descriptions of Python functions, the incorrect one is (B).

A. A function is a reusable group of statements

B. Each time you use the function, you need to provide the same parameters as input

C. The function is called through the function name

D. A function is a group of statements with a specific function

4. Among the following descriptions of Python global variables and local variables, the wrong one is (D).

A. Local variables are created and used inside the function and are released after the function exits.

B. Global variables generally refer to variables defined outside functions

C. After using the global reserved word declaration, the variable can be used as a global variable

D. When the function exits, the local variables still exist and can be used next time the function is called.

5. The incorrect way to open a file is (C).

A、f=open(‘test.txt’,’r’)                B、with open(‘test.txt’,’r’) as f

C、f= open(‘C:\Apps\test.txt’,’r’)        D、f= open(r‘C:\Apps\test.txt’,’r’)

6. Among the following descriptions of Python loop structures, the incorrect one is (D).

A. continue only ends this loop

B. The traversal structures in the traversal loop can be strings, files, combined data types, range() functions, etc.

C. Python builds loop structures through reserved words such as for and while

D. break is used to end the current statement, but does not jump out of the current loop body

7. Among the following descriptions of Python lists, the incorrect one is (A).

A. The length and content of the list can be changed, but the element types must be the same

B. Membership operations, length calculation and sharding can be performed on the list

C. The list can be indexed using both forward increasing sequence numbers and reverse decreasing sequence numbers.

D. You can use comparison operators (such as > or <, etc.) to compare lists

8.Data structures in Python are divided into variable types and immutable types. The following are immutable types (A).

A. Keys in dictionary B. List C. Set D. Dictionary

9. Among the following descriptions of Python file opening modes, the incorrect one is (D).

A. Read-only mode r

B. Overwrite mode w

C. Append writing mode a

D. Create write mode n

10. Among the following variable names, the one that does not comply with the Python language variable naming rules is (C).

A. keyword_33

B. keyword33_

C. 33_keyword

D. _33keyword

4. Programming questions (4 questions in total, 65 points)

1. Write a program, use * to print an isosceles right triangle as shown below, and take  a screenshot of  the test results . (15 marks)

*

* *

* * *

* * * *

for i in range(1,5):

for j in range(1,i+1):

print("*",end="")

print()

2. Write a number guessing game. (20 points)

It is required to use the randint() function of the random module to randomly generate numbers within 20. The user has five opportunities to enter the guessed number from the keyboard. If the guess is big, it will prompt you to guess a higher number. If you guess the small number, it will prompt you to guess a smaller number. If the guess is correct within the specified number of times, Exit the program, otherwise continue guessing until the number is exhausted. Take a screenshot  of the test results  .

from random import randint

number = randint(1,20)

for i in range(5):

guess = int(input("Please enter the number you guessed:"))

if guess > number:

print("big")

elif guess < number:

print("Small")

else:

print("Correct answer")

break

3. Classes and inheritance

(1) Create a Person class, initialize the name and age attributes in the constructor, create a get_name method with a return value to get the person's name, and a get_age function with a return value to get the person's age; (15 points)

class Person:

def __init__(self,name,age):

self.name = name

self.age = age

def get_name(self):

return self.name

def get_age(self):

return self.age

(2) Create the Student class to inherit the attributes and methods of the Person class, call the constructor of the base class in the constructor to initialize the common name and age attributes, and add the unique grade attributes of the Student class, course (including Chinese, mathematics, and English) door results) to initialize. Create a get_MaxScore method with a return value to return the highest score among the three subjects  Usage examples

s1 = Student('Xiao Ming',18,[93,68,76]) tests the three methods of the Student class, outputs the results, and screenshots the  results  . (15 marks)

class Student(Person):

def __init__(self,name,age,score):

Person.__init__(self,name,age)

self.score = score

def get_MinScore(self):

self.score.sort()

return self.score[-1]

s1 = Student("Xiao Ming",18,[93,68,76])

print(s1.get_name())

print(s1.get_age())

print(s1.get_MinScore())

Guess you like

Origin blog.csdn.net/i_like_cpp/article/details/132163630