Python-Quiz 5 (mooc)

1
1
point # 0033003400340034003600321587046573775 The following options are not the function of the function: ‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‬ ‬ ‬‬ ‬ reduce
programming complexity
to improve code execution speed of
code reuse
enhance code readability
correct answer is B
functions can not directly improve code execution speed.

2
1 min
# 0033003400340034003600321587046573776
output to the following procedure: ‪‬‮‬‪‬‭‬

def f(a,b):
a=4
return a+b
def main():
a=5
b=6
print(f(a,b),a+b)
main()

11 10

11 11

10 10

10 11

The correct answer D
here is that there are no global variables, and all operations are local variables of the function.

3
1 point
# 0033003400340034003600321587046573777
the following statement about the Python function is wrong: ‪‬‪‬‮‬‪‬‭‬

def func (a, b):
c = a ** 2 + b
b = a
return c
a = 10
b = 100
c = func (a, b) + a After
executing this function, the value of variable c is 200

After executing the function, the value of the variable b is 100

The function name is func

After executing the function, the value of the variable a is 10

The correct answer A.
There are no global variables here. Please execute the code in IDLE to observe the results.

4
1
minute # 0033003400340034003600321587046573778 The following description about the function call is correct: ‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‬‬ ‬‬ Python
built-in functions need to reference before calling the appropriate library
function need not be defined before calling, that is brought with like
function calls and can only occur in the same file
self-defined function calls must be defined before
the correct answer The
function definition must already exist before the D function is called, otherwise it cannot be executed.

The Python built-in functions are used directly, without the need to reference any modules.

5
1
minute # 0033003400340034003600321587046573779 The following is about the wrong description of the modular design: ‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‬ ‬ ‬‬ inter-module
relationship as simple, low coupling between the module
features a high degree of coupling is difficult multiplexing
should be as rational division of functional blocks, functional blocks high internal coupling
should divide function as reasonably possible Blocks, functional blocks have low internal coupling.
Correct answer D
High coupling within modules and low coupling between modules.

6
1
point # 0033003400340034003600321587046573780 The following description of recursion is wrong: ‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‬‪‬‪‬‬‬‬‬‬‬‬ ‬‬ write
simple
recursive procedure can have a non-recursive method for the preparation of
high-efficiency
must be a base case
the correct answer C
recursive program execution does not improve efficiency.

Any recursive program can become a non-recursive program through the stack or queue (this is an advanced application of the program).

7
1
point # 0033003400340034003600321587046573781 The following is wrong about the function statement: ‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‬‬‪‬‬‬‬‬ ‬ ‬‬ function
is called by the function name
function can be seen as some have the name of the subroutine
to use the function of its internal implementation must understand the principle
function is a piece with a specific function, reusable group of statements
correct answer C
calling function You don't need to know the internal implementation principle of the function, you only need to know the calling method (that is, the interface).

8
1
point # 0033003400340034003600321587046573783 Which option is wrong for the function definition? def
vfunc (a , b = 2):
def vfunc (* a, b):
def vfunc (a, b):
def vfunc (a, * b):
correct answer B
def vfunc (* a, b) is the wrong definition: * a Represents variable parameters. Variable parameters can only be placed at the end of function parameters.

9
1
point # 0033003400340034003600321587046573784 about the return statement, the following description is correct: functions
can not return statement
return only return a value
function must have a return statement
function can only have one return statement is
the correct answer a
function can contain zero or more return statements

10
1
min. # 0033003400340034003600321587046573787 the following recursive function on the base case statement is wrong: each
recursive function can have only one base case
base case is no longer recursive function recursive
depth-based recursive function determines the cases recursive
recursive function must have the base case
the correct answer a
each recursive There is at least one base case for a function, but there may be multiple base cases.

3600321587046604177
random password generation
described
complementary template programming code, the following functions: ‬‪‬‪‬‮‬‪‬‭‬

Taking the integer 17 as a random number seed, the user enters the integer N as the length, and generates 3 passwords with a length of N digits. Each digit of the password is a number. Each password is output on a separate line.

The random.randint () function is used to generate the password.

#请在...补充代码
import random

def genpwd(length):
    a = pow(10, length - 1)  # 定义一个下限
    b = pow(10, length) - 1  # 定义一个上限
    return "{}".format(random.randint(a, b))
length = eval(input())
random.seed(17)
for i in range(3):
    print(genpwd(length))

3600321587046623337
consecutive primes calculation
described
complementary template programming code, the following functions: ‬‪‬‪‬‮‬‪‬‭‬

Obtain the user input number N, calculate and output 5 prime numbers starting from N, single line output, comma between prime numbers, split.

Note: You need to consider that the number N entered by the user may be a floating point number, and the input should be an integer; no comma is required after the last output.

# 请在...补充一行或多行代码

def prime(m):
    if m < 2:
        return False
    else:
        end = int(pow(m, 0.5) + 1)
        for i in range(2, end):
            if m%i == 0:
                return False
        else:
            return True

n = eval(input())
if n != int(n):  # 因为可能输入有浮点数
    n = int(n) + 1
else:  
    n = int(n)
count = 5
while count > 0:
    if prime(n):
        if count > 1:
            print(n, end=',')
        else:
            print(n)
        count -= 1
    n += 1

Published 29 original articles · praised 0 · visits 477

Guess you like

Origin blog.csdn.net/qq_43771959/article/details/105568533