As the title says, given a stream of numbers, the program has to print the maximum number before reaching the first 0.
l = []
while True:
a=int(input())
if a==0:
print(max(l))
break
else:
l.append(a)
But as you can see, I actually print the max number in the list after the input reaches the 0.
I have no clue as to how to actually print the max number before reaching the first 0. Any ideas are most appreciated!
Edit: Screenshot from the source. Profound Academy
I tried it at the site. You get a runtime error. And the reason is that they have an input where the first number is 0, so you try max
on an empty list. In that case you're apparently supposed to print 0. It gets accepted if you change max(l)
to max(l, default=0))
.
Verdict: The task description or its input is buggy. I suggest you tell them and they should fix it.