Python-Quiz 4 (mooc)

1
1 point
# 0033003400340034003600321587046431657
for var in ___:
print (var)
Which option does not meet the grammatical requirements of the above program blank space?

{1;2;3;4;5}

“Hello”

(1,2,3)

range(0,10)

The correct answer A
for… in… after in needs to be an iterative type (combination type), {1; 2; 3; 4; 5} is not a valid data type for Python.

2
1 分
#0033003400340034003600321587046431658
for i in range(0,2):
print(i)

Which option is the output of the above program?

0 1

0 1 2

1 2

1

The correct answer A
range (0, 2) outputs two values: 0 and 1.

3
1 point
# 0033003400340034003600321587046431659
k = 10000
while k> 1:
print (k)
k = k / 2
Which option gives the number of output of the above program?

13

15

14

1000

The correct answer C
, please follow the program calculation or run the program in IDLE to obtain the result.

4
1
minute # 0033003400340034003600321587046431662 Which option is the three basic structures of the program? process
structures, objects Structure, function structure
Process structure, loop structure, branch structure
Sequential structure, loop structure, branch structure
Sequential structure, jump structure, loop structure
Correct answer C
No object structure, jump structure, process structure, etc.

5
1
minute # 0033003400340034003600321587046431663 Which option describes the loop structure incorrectly? cycling
is a program based on A running mode in which the condition judgment result is repeatedly executed backward. The
loop is a basic control structure of the program. The
conditional loop and the traversal loop structure are both basic loop structures. The
dead loop cannot be exited and has no effect. The
correct answer D. The
dead loop can be used for testing. Performance, the form of infinite loop can be used to break out, for example:

x = 10
while True:
x = x-1
if x == 1:
break
infinite loop has its effect.

6
1
point # 0033003400340034003600321587046431665 Regarding the Python statement P = -P, which option is described correctly?
assigned to the
P is equal to its negative number
P =
the absolute value of P. The
correct answer A
== the assignment symbol in Python, == is the equals symbol for judging equality.

7
1
point # 0033003400340034003600321587046431666 Which option is used to judge that the current Python statement is in the branch structure?
colon
braces
quotes
Indentation
Correct answer D
Indentation expresses hierarchical relationships.

8
1 point
# 0033003400340034003600321587046431667
Which option is the execution result of the following code?

for s in “PYTHON”:
if s==“T”:
continue
print(s,end="")

PYTHON

TT

PY

PYHON

The correct answer D
continue ends the current cycle, but does not jump out of the current cycle.

9
1
point # 0033003400340034003600321587046431669 Which option is the function used to generate random decimals in the random library? Random
()
randrange ()
getrandbits ()
randint ()
correct answer A
randint (), getrandbits (), randrange () all generate random integers, random () generates random decimals between 0 and 1.

10
1
min. # 0033003400340034003600321587046431671 Regarding try-except, which option is described incorrectly? NameError
is a Exception type is
used to catch and handle
the exception of the program. Using exception handling, the program will not make mistakes again.
Expressing the characteristics of a branch structure. The
correct answer C
uses exception handling. The program may run without error, but it may be logically possible. Error. Program error is a big concept, not only refers to code running errors, but also represents functional logic errors.

00321587046458596
Four-digit rose number
description ‭‬

The four-digit rose number is a four-digit self-power. The self-power number refers to an n-digit number, and the sum of the n-th power of the digits in each digit is equal to itself.

For example: when n is 3, there is 1 ^ 3 + 5 ^ 3 + 3 ^ 3 = 153, 153 is a self-power number when n is 3, and the 3-digit power number is called the daffodil number.

Please output all four-digit four-digit rose numbers, in order from small to large, with one line for each number.

for i in range(1000,10000):
    d=i%10
    b=i%1000//100
    c=i%100//10
    a=i//1000
    if i==a**4+b**4+c**4+d**4:
        print("{}".format(i))
s = ""
for i in range(1000, 10000):
    t = str(i)
    if pow(eval(t[0]),4) + pow(eval(t[1]),4) + pow(eval(t[2]),4) + pow(eval(t[3]),4) == i :
        print(i)

003600321587046493506 Sum of
prime numbers within 100
Description
Find the sum of all prime numbers within 100 and output.
It refers to a prime

Tip: You can judge whether each number within 100 is prime, and then sum.

sum=2
for i in range(100):
    for j in range(2,i): 
        if i%j==0:
            break
        elif i==(j+1):
            sum+=i
print("{}".format(sum))

Published 29 original articles · praised 0 · visits 478

Guess you like

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