Recently I started learning python and in parallel I solve problems with http://pythontutor.ru/ . And stuck on a task for cycles while.
Task text: Condition
A sequence consists of natural numbers and ends with the number 0. Determine the index of the largest element of the sequence. If there are several largest elements, print the index of the first one. The numbering of the elements starts from zero.
My solution code is:
max = 0 element = -1 index = -1 while element != 0: element = int(input()) if element > max: max = element index += 1 print(index) However, two options do not pass. For example: Input: 2 1 3 0 Answer: 2 (I get 1)
I see an error in general, but I don’t understand how to implement it, which would be solved not only if the numbers are not entered evenly in ascending / descending order (such options were all decided)