Advertisement
Guest User

RPS Game (Python)

a guest
Nov 29th, 2015
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.42 KB | None | 0 0
  1. #Rock Paper Scissors
  2.  
  3. from random import randint
  4.  
  5. def play_game():
  6.  
  7.     choices = {1: "Rock", 2:"Paper", 3:"Scissors"}
  8.  
  9.     user_score = 0
  10.     comp_score = 0
  11.     game_number = 1
  12.  
  13.     while True:
  14.  
  15.         comp_choice = randint(1, 3)
  16.         comp_choice = choices[comp_choice]
  17.         print "Game Number: " + str(game_number)
  18.         user_choice = raw_input("Choose rock(1), paper(2) or scissors(3). Or q to quit")
  19.        
  20.     if user_choice not in ["1", "2", "3", "q"]:
  21.             print "Invalid input"
  22.             continue
  23.         elif user_choice in ["q", 'Q', "quit"]:
  24.             print"Thanks for playing"
  25.             break
  26.  
  27.         user_choice = int(user_choice)
  28.         user_choice = choices[user_choice]
  29.  
  30.         print(user_choice + " vs " + comp_choice)
  31.  
  32.         if user_choice == comp_choice:
  33.             print("It's a tie!")
  34.             user_score += 1
  35.             comp_score += 1
  36.  
  37.         elif (user_choice=="Rock" and comp_choice=="Scissors") or (user_choice=="Paper"and comp_choice=="Rock") or (user_choice=="Scissors" and comp_choice=="Paper"):
  38.             print("You win!")
  39.             user_score += 1
  40.  
  41.         else:
  42.             print("The computer wins!")
  43.             comp_score += 1
  44.  
  45.         game_number += 1
  46.  
  47.  
  48.         print "User Score: " + str(user_score)
  49.         print "Computer Score: " + str(comp_score)
  50.         print("---------------------------------")
  51.         continue
  52.  
  53. play_game()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement