Python Forum
Looping if condition isnt met
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Looping if condition isnt met
#5
As Griboullis mentioned you are not comparing ints, you are comparing strings. When comparing strings '0' > '9' and '123456' < '2'. So your code works as long as you limit yourself to single digit numbers in the range 1 through 9. If you want to compare numbers you need to convert to a number. I would surround the conversion with try/except to prevent exiting the program if the user types something that isn't a number

It is odd defining a function inside of an if statement. It is valid Python, but really odd. It is also odd using recursion for something like this when a loop is simpler. I would write the code like this:
elif time_limit_ask[0] in ('r', 'R'):
    while True:
        try:
            if int(input("enter number ")) > int(input("enter number ")):
                break
        except ValueError:
            pass
    intro_1_complete = True
    time_limit_exists = True
Reply


Messages In This Thread
Looping if condition isnt met - by finndude - Oct-16-2020, 05:04 PM
RE: Looping if condition isnt met - by DPaul - Oct-16-2020, 05:22 PM
RE: Looping if condition isnt met - by Gribouillis - Oct-16-2020, 05:23 PM
RE: Looping if condition isnt met - by bowlofred - Oct-16-2020, 05:27 PM
RE: Looping if condition isnt met - by deanhystad - Oct-16-2020, 06:26 PM
RE: Looping if condition isnt met - by finndude - Oct-16-2020, 06:33 PM
RE: Looping if condition isnt met - by Skaperen - May-03-2021, 08:01 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  code isnt working. nezercat33 1 750 Mar-14-2025, 03:45 AM
Last Post: deanhystad
  Excel isnt working properly after python function is started IchNar 2 1,397 May-01-2024, 06:43 PM
Last Post: IchNar
  else condition not called when if condition is false Sandz1286 10 8,207 Jun-05-2020, 05:01 PM
Last Post: ebolisa
  [HELP] Nested conditional? double condition followed by another condition. penahuse 25 12,386 Jun-01-2020, 06:00 PM
Last Post: penahuse
  for some reason this isnt working lokchi2017 3 3,636 Aug-06-2018, 12:24 PM
Last Post: perfringo
  Why isnt this word length selector working Ivan 6 5,995 Mar-26-2017, 08:38 PM
Last Post: sparkz_alot

Forum Jump:

User Panel Messages

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