I am trying to know how many elements are greater than the previous number. im trying to input 1,5,2,4,3,0 but when it comes to the 4 and 3, the "times" does not add up. Could you tell me what i missed on my code? thanks a lot.
a = int(input())
b = -1
times = 0
while b != 0:
b = int(input())
if a > b:
times =+1
a = b
print(times)
Please, use proper tags when post code, traceback, output, etc. You have been advised to do so in your other thread.
See
BBcode help for more info.
if a > b:
equals the previous number is greater than the current number. If you use descriptive variable names it becomes obvious --> if previous > current. Also, this statement is incorrect
times =+1
Next time use
Python code tags, this time I have added them for you, but you have been
warned before.
# this
times =+1
# means times = 1
# and should probably be:
times += 1
Quote:# this
times =+1
# means times = 1
# and should probably be:
times += 1
Similar to __times = -1__ if you want a negative number.