Rock Paper Scissors Game in Python
Master Python with 70+ Hands-on Projects and Get Job-ready - Learn Python
Program 1
# Rock Scissors and Paper Game
import random
# Function to pick value from computer
def get_comp_choice():
return(random.choice(['rock','paper','scissors']))
# Function to pick value from user
def get_user_choice():
choice=input("Enter your choice('rock','paper','scissors')").lower()
while choice not in('rock','paper','scissors'):
print("Invalid choice enter again between ('rock','paper','scissors')")
choice=input("Enter your choice('rock','paper','scissors')").lower()
return(choice)
# Function for declare winner
def winner_declare(user_choice,comp_choice):
if(user_choice==comp_choice):
return(" Its a tie ... !")
if((user_choice=='rock' and comp_choice=='scissors') or (user_choice=='scissors' and comp_choice=='paper') or (user_choice=='paper' and comp_choice=='rock')):
return ("Congrats you win the game....")
else:
return (" Oops You lose the game....")
# Main calling
while(True):
print("--------Rock Scissors and Paper Game--------")
user=get_user_choice()
comp=get_comp_choice()
print("User Choice: ",user)
print("Computer Choice: ",comp)
print(winner_declare(user,comp))
choice=input("Want to play more....!(yes/no)").lower()
if(choice=='no'):
print("Thanks for playing Ok Bye Bye")
break
Did you know we work 24x7 to provide you best tutorials
Please encourage us - write a review on Google

