Python Forum
times greater number than the previous
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
times greater number than the previous
#1
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)


User has been warned for this post. Reason: No BB code even after advised
Reply
#2
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 you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
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
Reply
#4
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
Reply
#5
Quote:
# this
times =+1
# means times = 1
# and should probably be:
times += 1
Similar to __times = -1__ if you want a negative number.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  problem with ‘>’ (i.e. greater than) sign AOCL1234 2 1,904 Jun-30-2020, 09:32 PM
Last Post: Yoriz
  Find 'greater than' items in list johneven 2 4,430 Apr-05-2019, 07:22 AM
Last Post: perfringo
  Find how many times a user played an artist and how many times disruptfwd8 1 2,557 May-04-2018, 08:32 AM
Last Post: killerrex
  Search for Player ID and return games played and number of times disruptfwd8 3 3,378 May-03-2018, 06:45 PM
Last Post: disruptfwd8
  The int that appears an odd number of times. MeeranRizvi 6 6,473 Dec-30-2016, 09:54 AM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020