1
https://git.io/snakify
source link: https://gist.github.com/nptit/1f9396aadb48d49f3f1497592e8b1638
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Update on 06_10_seq_index_of_max.py
The output value always comes one value lesser
max = 0
i = 1 # change i value to 1
max_i = 0
a = int(input())
while a != 0:
if a > max:
max = a
max_i = i
a = int(input())
i += 1
print(max_i)
Alternative code
max = 0
index_of_max = -1
element = -1
len = 1
while element != 0:
element = int(input())
if element > max:
max = element
index_of_max = len
len += 1
print(index_of_max)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK