【发布时间】:2017-06-08 22:53:52
【问题描述】:
对不起,我对如何解决这个问题感到困惑......
程序采用一系列独立且随机的 int 输入,将每个新 int 与前一个 int 进行比较(更高、更低、相等):例如,第一个数字 = 10,下一个数字 = 5,输出 =降低。这个循环直到用户输入 [0]
但我现在想更改它,以便所有输出都在末尾,而不是每对之后的 1。假设整体输入是 2、3、6、6、5、1 [0]:打印语句应该只在 [0] 之后,这会说,例如,higher Higher 等于 lower lower(全部在一个语句中)。
我尝试过的事情... print(a) 但当然 (a) 会重新分配给每个新号码.....尝试过(新手错误):如果 b
我的代码:
z = 0
done = False
a = int(input("Enter first number: "))
while not done:
b = int(input("Enter next number [0 = done]: "))
if b != z: #while program not done
if b > a:
print("higher")
if b == a:
print("equal")
if b < a:
print("lower")
a = b #second number becomes first and repeat
else:
done = True
非常感谢任何帮助。谢谢。
【问题讨论】:
标签: string python-3.x loops int output