0

I need help with adding a code after the elif answer == "y": that starts the app again from the beginning

answer = input("Run again? (y/n): ")
import sys
if answer == "n":
    print("Goodbye.")
    sys.exit   
elif answer == "y":
sudo_coffee
  • 888
  • 1
  • 12
  • 26

1 Answers1

1
import sys

status = True
while(status):
    answer = input("Run again? (y/n): ")
    if answer == "n":
        status = False   
    elif answer == "y":
        status = True
print("Goodbye.")
sys.exit
syguts
  • 46
  • 4
  • 1
    Tip: `status = answer == 'y'` – OneCricketeer Oct 16 '16 at 19:32
  • What's the benefit of `while(status):` as opposed to `while status:` ? – MichaelMaggs Oct 16 '16 at 19:38
  • 2
    @MichaelMaggs There is no benefit. They should not be there. If you use any good editor, you will typically get a warning to remove those kinds of redundant parentheses. – idjaw Oct 16 '16 at 19:41
  • I tried your code but it doesn't work smoothly, when I click no it exits the program without saying "Good Bye" but when I say Yes it says "Good Bye" and restarts just the last part "Run again? (y/n):". Also, I begin learning Python so if you could me how 'status' and 'while' work I would be grateful since I couldn't get it. – Osama Raafat Oct 17 '16 at 20:38