Write a program to add ten numbers enter by user in a loop. (For loo

huangapple go评论79阅读模式
英文:

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(&quot;Enter only integer value::&quot;))))
a= List[0]
for x in range(10):
    if a &lt; List[x]:
        print(a, &quot;Is the largest number&quot;)

答案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(&quot;Enter only integer value::&quot;)))

答案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.

huangapple
  • 本文由 发表于 2023年5月30日 00:45:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/76359025.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定