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
#2
Maybe try something like

#! /usr/bin/env python3

def play():
    while True:
        play_again = input('Play Again? ')
        if play_again.lower() in ['y', 'yes']:
            print('I am playing agin')
            # Do some stuff
        elif play_again.lower() in ['n', 'no']:
            print('Thanks for playing!')
            break
        else:
            print('Please type yes or no')
            continue

play()
Output:
Play Again? yes I am playing agin Play Again? mm Please type yes or no Play Again? no Thanks for playing!
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


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 menator01 - Oct-12-2021, 09:31 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  ChromeDriver breaking Python script genericusername12414 1 422 Mar-14-2024, 09:39 AM
Last Post: snippsat
  Openpyxl module breaking my code EnderSM 5 1,219 May-26-2023, 07:26 PM
Last Post: snippsat
  breaking out of nested loops Skaperen 3 1,320 Jul-18-2022, 12:59 AM
Last Post: Skaperen
  How to use += after breaking for loop? Frankduc 2 1,568 Dec-31-2021, 01:23 PM
Last Post: Frankduc
  breaking a large program into functions, not acting as expected Zane217 9 3,144 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,427 Sep-04-2021, 04:51 PM
Last Post: imillz
Exclamation Help in breaking bytes into bits through masking and shifting kamui123 9 4,787 Jan-11-2021, 07:42 AM
Last Post: kamui123
  breaking outof nexted loops Skaperen 4 3,229 Feb-07-2020, 02:04 AM
Last Post: Skaperen
  Breaking While Loop JustWonderful 4 3,190 Oct-28-2019, 01:12 AM
Last Post: JustWonderful
  (Python help) Change in logic not breaking 'while' loop? btcg2807 1 1,939 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