Ending the Program - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Ending the Program (/thread-26923.html) |
Ending the Program - Twoshawns - May-18-2020 So right now I am trying to figure out how to prompt the user to type in yes or no in order to either continue or end the game. I have the prompt but the program will not end only continue, please help. Here is my code: [python] import random import time def main(): print("This is a rock, paper, scissor game") while play_again.upper == 'Y': return True return False play_again = True def rps(): print("This is a rock, paper, scissor game") time.sleep(3) move_list = ['Rock', 'Paper', 'Scissors'] while play_again == True: for comp in move_list: user = input('What\'s your hand?: ') user = user.capitalize() comp = random.choice(list(move_list)) if comp == 'Rock' and user == 'Paper': print("Computer throws " + comp + " you have thrown " + user + "!") print("You Win!") elif comp == 'Rock' and user == 'Rock': print("Computer throws " + comp + " you have thrown " + user + "!") print("It's a draw") elif comp == 'Rock' and user == 'Scissor': print("Computer throws " + comp + " you have thrown " + user + "!") print("You Lose!") elif comp == 'Scissors' and user == 'Paper': print("Computer throws " + comp + " you have thrown " + user + "!") print("You Lose!") elif comp == 'Scissors' and user == 'Rock': print("Computer throws " + comp + " you have thrown " + user + "!") print("You Lose!") elif comp == 'Scissors' and user == 'Scissors': print("Computer throws " + comp + " you have thrown " + user + "!") print("It's a Draw!") elif comp == 'Paper' and user == 'Paper': print("Computer throws " + comp + " you have thrown " + user + "!") print("It's a Draw!") elif comp == 'Paper' and user == 'Rock': print("Computer throws " + comp + " you have thrown " + user + "!") print("You Lose!") elif comp == 'Paper' and user == 'Scissors': print("Computer throws " + comp + " you have thrown " + user + "!") print("You Win!") else: print("You messed up the program dummy") print(comp) answer = input("Would you like to play again?: ") rps() main() RE: Ending the Program - DT2000 - May-19-2020 You can use a messagebox to promto for a Yes or No response if you are going to design this to run in a GUI. Example: import tkinter as tk from tkinter import Label from tkinter import Button from tkinter import messagebox root = tk.Tk() root.geometry('300x300') label=Label(root, text= 'Your gamre application is running') label.pack() def popup(): your_popup = messagebox.askyesno('Your Game Name','Do you want to continue?') if your_popup == True: return else: root.destroy() button=Button(root, text='Press', command=popup) button.pack() root.mainloop() RE: Ending the Program - menator01 - May-19-2020 call sys.exit() |