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 like our efforts? If Yes, please give DataFlair 5 Stars on Google

courses

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

Leave a Reply

Your email address will not be published. Required fields are marked *