This repository was archived by the owner on Apr 24, 2025. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -9,14 +9,17 @@ def toss_coin():
99
1010def main ():
1111 while True :
12+ flag = False # Declaring a variable which will be used afterwards to break out of 2 nested while loops
13+ # at the same time
1214 # Clears the shell/terminal (where all the text is)
1315 os .system ("cls" )
1416
1517 answer = input ("Pick a side for the coin toss (heads/tails): " )
1618
1719 # Input validation
1820 if answer .lower () not in ["heads" , "tails" ]:
19- print ("Invalid input. Please enter 'heads' or 'tails'." )
21+ # removed the print statement here because its not required since the while loop clears
22+ # the statement anyways
2023 continue
2124
2225 result = toss_coin ()
@@ -29,8 +32,17 @@ def main():
2932 print ("OOF. Better luck next time." )
3033
3134 # Ask the user if they want to play again
32- answer_y = input ("Wanna play again? (yes/no): " )
33- if answer_y .lower () != "yes" :
35+ while True :
36+ answer_y = input ("Wanna play again? (yes/no): " )
37+ if answer_y .lower () == "no" :
38+ flag = True
39+ break
40+ elif answer_y .lower () == "yes" :
41+ break # if answer_y is "yes" then break out of only the innermost while loop and start the game again
42+ else :
43+ continue
44+
45+ if flag : # Checking if the flag variable is True
3446 break
3547
3648
You can’t perform that action at this time.
0 commit comments