在 while 循环中重置最大值



我正在尝试确定值超过上一个输入的次数。 以下代码适用于 1,7,9,0(两次乘以 7,超过 1,9 超过 7),但在 1,5,2,4,3,0 上失败。我知道这是因为我将最大值设置为 5,当然 2 和 4 小于 5。我不知道该怎么做才能将最大值"重置"回 1

a = int(input())
counter = 0
highest = 1
while a != 0:
    if a > highest:
        highest = a
        counter += 1
    a=int(input())
# need to reset highest to next input of 'a'
print(counter)

感谢您的耐心等待。还是个老家伙,看我是不是脑残了。对不起,如果这是一个愚蠢的问题,我只是没有看到它。此外,我遵循的课程暗示我不能使用任何东西,但如果,否则,虽然没有列表或任何东西

first_num = int(input())
incremental_count = 0
while first_numv != 0:
    second_num = int(input())
    if second_num != 0 and first_num < second_num:
        incremental_count += 1
    first_num = second_num
print(incremental_count)

一旦我用我的方式解决了它,这就是给出的答案,它更聪明、更简单!

最新更新