英文:
Write a program to add ten numbers enter by user in a loop. (For loo
问题
TypeError: '<' not supported between instances of 'NoneType' and 'NoneType'
任务 4:在循环中从用户获取十个数字并找到最大的数字
List = []
for i in range(1, 11):
List.append(print(int(input("仅输入整数值::"))))
a = List[0]
for x in range(10):
if a < List[x]:
print(a, "是最大的数字")
英文:
TypeError: '<' not supported between instances of 'NoneType' and 'NoneType'
# Task 4: Take ten number from user in a loop and find the largest number
List=[]
for i in range(1,11):
List.append(print(int(input("Enter only integer value::"))))
a= List[0]
for x in range(10):
if a < List[x]:
print(a, "Is the largest number")
答案1
得分: 3
print()
总是返回 None
。所以你的列表包含了许多 None
值。
input()
负责打印提示,所以你不需要 print()
。
修改你的附加循环以去掉 print()
:
List.append(int(input("只输入整数值:")))
英文:
print()
always returns None
. So your List contains a bunch of None values.
input()
takes care of printing the prompt, so you don't need print()
anyway.
Change your append loop to take out the print()
:
List.append(int(input("Enter only integer value::")))
答案2
得分: 0
你的输入中有一个像@JohnGordon所说的打印。你还需要遍历a
。你目前只通过索引测量了你的list
中的第一个值。
英文:
You have a print inside your input like @JohnGordon said. You also have to iterate through a
. You are currently only measuring the 1st value in your list
by indexing.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论