【发布时间】:2022-01-12 07:24:38
【问题描述】:
我们的任务是用 python 编写一个程序,要求用户输入多个数字。 主题是while循环,所以我们只能使用while循环和if语句。 当用户想停止输入数字时,用户需要输入'-1'。 一旦完成,程序必须返回用户输入数字的平均值。
这是我目前所拥有的: #task 13-while.py
#first the program will explain to the user that the user can keep
#entering numbers until -1 occurs.
num = int(input('''please enter any number of your choice\n
please enter -1 to stop entry and run program'''))
num_count = 0
while num > -1:
num_count = num_count + 1
average = sum(num)/num_count
if num == -1:
print("the average of the numbers you have entered is"+ average)
对python非常缺乏经验,非常感谢所有帮助。
【问题讨论】:
标签: python input while-loop