Advertisement
MrsMcLead

ECS Rock, Paper, Scissors

Nov 19th, 2013
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.15 KB | None | 0 0
  1. from tkinter import*
  2. import tkinter.simpledialog
  3. import tkinter.messagebox
  4. import random
  5.  
  6. root = Tk()
  7. w = Label(root, text="Rock Paper Scissors")
  8. w.pack()
  9.  
  10. ROCK = 0
  11. PAPER = 1
  12. SCISSORS = 2
  13.  
  14. computer = random.randint(0,2)
  15.  
  16. user = tkinter.simpledialog.askinteger("Choose wisely", "Enter 0 for ROCK, 1 for PAPER, or 2 for SCISSORS.")
  17.  
  18. # 1. this code will tell if the computer throws ROCK.  add code to tell
  19. #    you when the computer throws SCISSORS and PAPER.  It will be very similar.
  20. if computer == ROCK:
  21.     tkinter.messagebox.showinfo("Computer", "The computer throws ROCK")
  22.  
  23.  
  24. # 2. this is the code to determine who wins if the user picks ROCK.  Write the
  25. #    code below it to handle if the user has PAPER and if the user has SCISSORS.
  26. #    the code will look very similar.
  27. if user == ROCK:
  28.     if computer == PAPER:
  29.         tkinter.messagebox.showinfo("Rock vs Paper", "You lose, PAPER covers ROCK!")
  30.     elif computer == ROCK:
  31.         tkinter.messagebox.showinfo("Rock vs Rock", "It's a tie, we both have ROCK!")
  32.     else: #computer == SCISSORS
  33.         tkinter.messagebox.showinfo("Rock vs SCISSORS", "You win, ROCK breaks SCISSORS!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement