File tree Expand file tree Collapse file tree
Rock, Paper, Scissors Game Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <div align =" center " >
2+
3+ # Rock, Paper, Scissors Game
4+
5+ </div >
6+
7+ ### Description:
8+ This Python script allows the user to play the classic Rock, Paper, Scissors game against the computer.
9+
10+ ### How to Use:
11+ 1 . Run the script in a Python environment.
12+ 2 . Enter your choice (rock, paper, or scissors) when prompted.
13+ 3 . The script will randomly generate the computer's choice and determine the winner based on the rules of the game.
Original file line number Diff line number Diff line change 1+ import random
2+
3+
4+ def play_game (user_choice ):
5+ options = ["rock" , "paper" , "scissors" ]
6+ computer_choice = random .choice (options )
7+ print (f"Computer chooses: { computer_choice } " )
8+ if user_choice == computer_choice :
9+ return "It's a tie!"
10+ elif (user_choice == "rock" and computer_choice == "scissors" ) or \
11+ (user_choice == "paper" and computer_choice == "rock" ) or \
12+ (user_choice == "scissors" and computer_choice == "paper" ):
13+ return "You win!"
14+ else :
15+ return "Computer wins!"
16+
17+
18+ def main ():
19+ user_choice = input ("Enter your choice (rock/paper/scissors): " ).lower ()
20+ if user_choice not in ["rock" , "paper" , "scissors" ]:
21+ print ("Invalid choice!" )
22+ else :
23+ print (play_game (user_choice ))
24+
25+
26+ if __name__ == "__main__" :
27+ main ()
You can’t perform that action at this time.
0 commit comments