Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Ending the Program
#1
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()
Reply
#2
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()
"Often stumped... But never defeated."
Reply
#3
call sys.exit()
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
Gaming Collection
Homepage
my-python
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python: Call function with variabele? Ending in error. efclem 5 1,046 Apr-22-2020, 02:35 PM
Last Post: buran
  ending process hrparra 1 823 Jan-07-2020, 07:40 PM
Last Post: ibreeden
  Ending loop with string (capital & lowercase) MattWilk97 3 2,144 Oct-22-2017, 09:13 PM
Last Post: sparkz_alot

Forum Jump:

User Panel Messages

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