0% found this document useful (0 votes)
3 views6 pages

Python

The document contains a Python program for the Rock, Paper, Scissors game, which allows users to play against the computer. It includes functions for getting user and computer choices, determining the winner, and managing the game flow. The program is designed to be user-friendly with clear outputs and prompts for replaying the game.

Uploaded by

zilerehmanlatif
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views6 pages

Python

The document contains a Python program for the Rock, Paper, Scissors game, which allows users to play against the computer. It includes functions for getting user and computer choices, determining the winner, and managing the game flow. The program is designed to be user-friendly with clear outputs and prompts for replaying the game.

Uploaded by

zilerehmanlatif
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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.

You might also like