NumOfInt = int(input("How many numbers would you like to add up? : "))
total = 0
for i in range (NumOfInt):
newnum = int(input("Enter a number! : "))
total += newnum
print("Your total is: " + str(total))
这将把他们的输入加到总数中,直到他们输入的数字超过NumOfInt:
How many numbers would you like to add up? : 4
Enter a number! : 1
Enter a number! : 2
Enter a number! : 3
Enter a number! : 4
Your total is: 10
我想这就是你要问的:
使用for循环编写一个程序,询问用户要加多少个数字。然后,它会问他们这个数量的次数为一个数字,这将被添加到总数。然后打印出来。你知道吗
如果是这样的话,那么我相信您只需要向用户请求这个数量的数字,并以与您的类似的方式编写for循环:
这将把他们的输入加到总数中,直到他们输入的数字超过NumOfInt:
我希望这有帮助:)
相关问题 更多 >
编程相关推荐