Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Rock Paper Scissors
- from random import randint
- def play_game():
- choices = {1: "Rock", 2:"Paper", 3:"Scissors"}
- user_score = 0
- comp_score = 0
- game_number = 1
- while True:
- comp_choice = randint(1, 3)
- comp_choice = choices[comp_choice]
- print "Game Number: " + str(game_number)
- user_choice = raw_input("Choose rock(1), paper(2) or scissors(3). Or q to quit")
- if user_choice not in ["1", "2", "3", "q"]:
- print "Invalid input"
- continue
- elif user_choice in ["q", 'Q', "quit"]:
- print"Thanks for playing"
- break
- user_choice = int(user_choice)
- user_choice = choices[user_choice]
- print(user_choice + " vs " + comp_choice)
- if user_choice == comp_choice:
- print("It's a tie!")
- user_score += 1
- comp_score += 1
- elif (user_choice=="Rock" and comp_choice=="Scissors") or (user_choice=="Paper"and comp_choice=="Rock") or (user_choice=="Scissors" and comp_choice=="Paper"):
- print("You win!")
- user_score += 1
- else:
- print("The computer wins!")
- comp_score += 1
- game_number += 1
- print "User Score: " + str(user_score)
- print "Computer Score: " + str(comp_score)
- print("---------------------------------")
- continue
- play_game()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement