Python Forum
How to fix while loop breaking off
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to fix while loop breaking off
#4
"Do some stuff" is where you call your function that plays the game.
def play_game():
    '''code for playing my game'''

while True:
    inp = input('Would you like to play my wonderful game? ')
    if len(inp) == 0 or inp[0].upper() != 'Y':
        break
    play_game()
This loop requires the user to input some kind of YES, Yes, yes, yup, y, Y to play otherwise it exits. If you want to play the game at least once you make a slight change.
def play_game():
    '''code for playing my game'''

while True:
    play_game()
    inp = input('Would you like to play my wonderful game? ')
    if len(inp) == 0 or inp[0].upper() != 'Y':
        break
Reply


Messages In This Thread
How to fix while loop breaking off - by raphy11574 - Oct-12-2021, 09:01 AM
RE: How to fix while loop breaking off - by deanhystad - Oct-12-2021, 12:56 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  ChromeDriver breaking Python script genericusername12414 1 359 Mar-14-2024, 09:39 AM
Last Post: snippsat
  Openpyxl module breaking my code EnderSM 5 1,141 May-26-2023, 07:26 PM
Last Post: snippsat
  breaking out of nested loops Skaperen 3 1,269 Jul-18-2022, 12:59 AM
Last Post: Skaperen
  How to use += after breaking for loop? Frankduc 2 1,521 Dec-31-2021, 01:23 PM
Last Post: Frankduc
  breaking a large program into functions, not acting as expected Zane217 9 3,095 Sep-18-2021, 12:37 AM
Last Post: Zane217
  Need to run 100+ Chrome’s with Selenium but can’t get past ~15 without breaking imillz 0 1,397 Sep-04-2021, 04:51 PM
Last Post: imillz
Exclamation Help in breaking bytes into bits through masking and shifting kamui123 9 4,659 Jan-11-2021, 07:42 AM
Last Post: kamui123
  breaking outof nexted loops Skaperen 4 3,182 Feb-07-2020, 02:04 AM
Last Post: Skaperen
  Breaking While Loop JustWonderful 4 3,138 Oct-28-2019, 01:12 AM
Last Post: JustWonderful
  (Python help) Change in logic not breaking 'while' loop? btcg2807 1 1,918 Sep-18-2019, 09:43 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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