Python Project – Rock, Scissor, Paper Game

Master Python with 70+ Hands-on Projects and Get Job-ready - Learn Python

Program 1

# Rock Scissors and Paper Game
import random

#function for computer choice
def get_comp_choice():
      return(random.choice(['rock','paper','scissors']))

#function for user choice
def get_user_choice():
      choice=input("Enter your choice between('rock','paper','scissors')").lower()
      while choice not in('rock','paper','scissors'):
            print("Invalid choice please enter('rock','paper','scissors')")
            choice=input("Enter your choice between('rock','paper','scissors')").lower()
      return choice

#function for decalre winner
def declare_winner(userchoice,compchoice):
      if(userchoice==compchoice):
            return " Its a tie !"
      else:
            if((userchoice=='rock' and compchoice=='scissors') or (userchoice=='scissors' and compchoice=='paper')  or (userchoice=='paper' and compchoice=='rock')):
                  return " You are Winner !"
            else:
                  return " Computer is a Winner !"

#Main Method
while(True):
    print("---------Rock Scissors and Paper Game---------")
    user_choice=get_user_choice()
    comp_choice=get_comp_choice()
    print("{User Choice is: }",user_choice)
    print("{Computer Choice is: }",comp_choice)
    print(declare_winner(user_choice,comp_choice))
    user_choice=input("Want to play more(yes/no)").lower()
    if(user_choice=='no'):
          break

print("Ok Good Bye.......!")

 

We work very hard to provide you quality material
Could you take 15 seconds and share your happy experience 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 *