导航菜单
首页 >  » 正文

python选择题/简答题 Python练习题

python选择题/简答题

1. True的选项是A
2. True的选项是A
3. 输出是16 range(2,10)>2,3,4,5,6,7,8,9 循环了3次,X分别为2,3,4
4. 输出的结果是(-2,3,5)
5. people = [{name: Mary, height: 160},{name: Isla, height: 80},

{name: Sam}]
height=0
n=0
for i in range(len(people)):
     if isinstance((people[i].get(height)),int):
        n=n 1
        height=people[i].get(height)  height      
else:
     print(人员的平均身高为%s% (height/n))

Python练习题

首先 range是reversed word 在这里你可以理解为python保留词汇 也就是说你给一个变量赋值时 不能命名其为range 因为你下载的python里已经有了range的用法和相关操作规则 wiki中的定义为a reserved word (also known as a reserved identifier) is a word that cannot be used as an identifier, such as the name of a variable, function, or label (也就是前面我所解释的 当然 wiki更权威 相信你也能读懂 )

其他的reserved word 可以随便举例 比如 random in for print 等等 都可以

python 习题

有一个巧妙的解法
for i in zip(*grid):
  print .join(i)zip(*grid) 将每一列并在一起,
print .join(i) 列表中的元素合并,然后输出,如果是Python3 这句改成print(.join(i))

比较笨的方法可以写两重循环,组个字符输出。

相关推荐: