Name: Zillerehman
Subject: programming and data science
Department: chemical engineering
Roll no: 12
Submitted by: zillerehman
Submitted to: Burhan Ahmad
1. Write a Python program for the classic Rock, Paper,
Scissors game. 2. Make sure the code is clean and
produces clear outputs when run.
import random
def get_user_choice():
choices = ['rock', 'paper', 'scissors']
while True:
user_input = input("Choose rock, paper, or
scissors: ").lower()
if user_input in choices:
return user_input
else:
print("Invalid choice. Please try again.")
def get_computer_choice():
choices = ['rock', 'paper', 'scissors']
return [Link](choices)
def determine_winner(user_choice, computer_choice):
if user_choice == computer_choice:
return "It's a tie!"
elif (user_choice == 'rock' and computer_choice ==
'scissors') or \
(user_choice == 'scissors' and computer_choice ==
'paper') or \
(user_choice == 'paper' and computer_choice ==
'rock'):
return "You win!"
else:
return "Computer wins!"
def play_game():
print("Welcome to Rock, Paper, Scissors!")
while True:
user_choice = get_user_choice()
computer_choice = get_computer_choice()
print(f"\nYou chose: {user_choice}")
print(f"Computer chose: {computer_choice}")
result = determine_winner(user_choice,
computer_choice)
print(result)
# Ask if the user wants to play again
play_again = input("\nDo you want to play again?
(yes/no): ").lower()
if play_again != 'yes':
print("Thanks for playing! Goodbye.")
break
if __name__ == "__main__":
play_game()
Running:
Welcome to Rock, Paper, Scissors!
You chose: paper
Computer chose: rock
You win!
You chose: scissors
Computer chose: paper
You win
You chose: paper
Computer chose: scissors
Computer wins!
You chose: scissors
Computer chose: paper
You win!
You chose: paper
Computer chose: scissors
Computer wins!
You chose: scissors
Computer chose: scissors
It's a tie!
You chose: rock
Computer chose: paper
Computer wins!
Thanks for playing! Goodbye.