SHARE
TWEET

Untitled

a guest Nov 15th, 2017 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # lets users play 2-player rock-paper-scissors
  2. # teaching points:
  3.   # infinite game loops and breaking statements
  4.  
  5. def compare(u1, u2): # tests and returns results of rock paper scissors
  6.   if u1 == u2:
  7.     print("It's a tie!")
  8.   elif u1 == 'rock': # accounts for all possible results
  9.     if u2 == 'scissors':
  10.       print("{} won because {} ROCKs!".format(user1, user1))
  11.     else:
  12.       print("{} won with paper!".format(user2))
  13.      
  14.   elif u1 == 'scissors':
  15.     if u2 == 'paper':
  16.       print("{} won with scissors!".format(user1))
  17.     else:
  18.       print("{} won because {} ROCKs!".format(user2, user2))
  19.  
  20.   elif u1 == 'paper':
  21.     if u2 == 'rock':
  22.       print("{} won with paper!".format(user1))
  23.     else:
  24.       print("{} won with scisors!".format(user2))
  25.   else: # rejects all other responses
  26.     print("Hey! Choose rock, paper or scissors!")
  27.    
  28.  
  29. def game():
  30.   while True: # creates game loop to be quit with 'n'
  31.    
  32.     # asks users for rock/paper/scissors
  33.     user1_choice = input("\n{}, do you choose rock, paper or scissors? ".format(user1)).lower()
  34.     user2_choice = input("{}, do you choose rock, paper or scissors? ".format(user2)).lower()
  35.    
  36.     compare(user1_choice, user2_choice)
  37.     # asks user if they want to play again
  38.    
  39.     play_again = input("Do you want to play again? Y/n").lower()
  40.     if play_again == 'n':
  41.       print("Okay, bye!")
  42.       break
  43.    
  44.  
  45. # asks users for name
  46. print("Welcome to rock-paper-scissors for the irrationally lazy!")
  47. user1 = input("What's your name? ")
  48. user2 = input("And your name? ")
  49.  
  50. game()
RAW Paste Data
Top