在while循环中重置最大值

时间:2017-10-12 08:59:03

标签: python-3.x

我正在尝试确定值超过之前输入的次数。以下代码适用于1,7,9,0(两次7,超过1,9,超过7),但在1,5,2,4,3,0上失败。我知道这是因为我将最大值设置为5,当然2和4都小于5.我无法弄清楚该怎么办" reset"最大值回到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)

感谢您的耐心等待。仍然是一个老人,看看我是否还在脑死亡。对不起,如果这是一个愚蠢的问题,我只是没有看到它。此外,我关注的课程暗示我不能使用任何东西,除非是,否则,没有列表或任何东西

1 个答案:

答案 0 :(得分:0)

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)

一旦我按照自己的方式解决了问题,这就是给出的答案,它更聪明,更简单!

相关问题