PYTHON-模拟练习题目集合

2024-01-18 15:33:39 浏览数 (1)

1. Which of the following expression is Illegal?

O A.['12.56'] * 7 O B. int(7.4) 7.4 O C.['a','b','c']-['a'] O D.str(1.32)*5

考查:列表,整数,字符串的运算规则


在Python中,列表的加法运算是将两个列表拼接成一个新的列表,例如:

代码语言:javascript复制
a = [1, 2, 3]
b = [4, 5, 6]
c = a   b # [1, 2, 3, 4, 5, 6]

列表的乘法运算是重复一个列表多次得到一个新的列表,例如:

代码语言:javascript复制
a = [1, 2, 3]
b = a * 3 # [1, 2, 3, 1, 2, 3, 1, 2, 3]

列表不存在减法和除法运算。->选c

2.Function defining

Please define a function which can find out the all multiples of 3 (3的倍数) from 0 to nand return the sum of those mutiples.

Header of the function:

在这里描述函数接口。

例如:def acc_three(n): n is larger than 3 and smaller than 1000

代码语言:javascript复制
def acc_three(n):
    sum = 0
    for i in range (3,n 1):
        if i % 3 == 0:
            sum  = i
    return sum

#


	

0 人点赞