编写一个程序,要求用户输入 5 个数字,并输出这些数字中最大的和最小的。因此,例如,如果用户输入数字 2456 457 13 999 35,输出将如下所示:最大数字是 2456,最小数字是 35
在 Python 中
a = input()
first = int(a)
b = input()
second = int(b)
c = input()
third = int(c)
d = input()
fourth = int(d)
if a > b or a > c or a > d:
print ('the larges number' + a)
elif a < b or a < c or a < d:
print ('the smallest number' +a )
elif b > a or b > c or b > d:
print ('the larges number' + b)
elif b < a or b < c or b < d:
print ('the smallest number is' + b )
elif d > a or d > b or d > c:
print ('the biggest number is' + d )
elif d < a or d < b or d < c:
print ('the smallest numbet is'+ d)
else:
我想出了这个主意,但我认为它不能正常工作
数,输出最大的
这些数字和这些数字中最小的一个。
在我的模块手册中我有这个例子
num = 0
while num < 100:
num = num + 5
print(str(num))
print(’Done looping!’)
但是在此之后,没有进一步解释我如何解决这个问题。请你帮助我好吗 ?
我需要通过使用 while 循环来解决问题,我对编程很陌生,请帮忙。
原文由 stefan s 发布,翻译遵循 CC BY-SA 4.0 许可协议
您可以通过循环执行
input
来解决它,然后使用内置的 min 和 max 函数显示最大和最小值:看来你需要一个
while
循环,在这种情况下只需使用一个计数器: