【发布时间】:2020-06-08 10:39:06
【问题描述】:
我尝试创建一个 while 循环函数,其中程序采用浮点数(米)的六个单独的用户输入。如果数字大于零,则接受每个输入。如果 number 小于零,则每个输入都被忽略。
虽然循环应该最多计算六个用户输入然后打印:
- 成功输入的数量
- 关闭的输入数
- 最大的输入是
- 所有输入的平均值是
我的挑战是我不明白如何使用 while 循环,以便它在输入一定数量之前计数,然后停止
以下是示例输出:
Give the latest user input: 86.2
Give the latest user input: 81.2
Give the latest user input: 79.6
Give the latest user input: 89.3
Give the latest user input: -1
Give the latest user input: 86.5
There were 5 succesful input(s).
There were 1 dismissed input(s).
The highest input was 89.3.
The mean of all inputs was 84.56 meters.
【问题讨论】:
-
到目前为止你的代码是什么?您是否尝试过在每次执行时计数的
while循环之前创建一个变量? -
可以使用
for i in range(6):循环6次。
标签: python function while-loop count