0% found this document useful (0 votes)
16 views1 page

Rock Scissor Paper Code

By python

Uploaded by

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

Rock Scissor Paper Code

By python

Uploaded by

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

import random

while True:
print("Welcome to Rock, Paper, Scissors!")
player_choice = input("Choose your weapon:\n1. Rock\n2. Paper\n3. Scissors\
nEnter your choice (1-3): ")

# Input validation
if player_choice not in ["1", "2", "3"]:
print("Invalid choice. Please enter a number between 1 and 3.\n")
continue

player_choice = int(player_choice)

# Computer's choice
computer_choice = random.randint(1, 3)

# Display choices
print("\nYou chose:", end=" ")
if player_choice == 1:
print("Rock")
elif player_choice == 2:
print("Paper")
else:
print("Scissors")

print("Computer chose:", end=" ")


if computer_choice == 1:
print("Rock")
elif computer_choice == 2:
print("Paper")
else:
print("Scissors")

# Determine the winner


if player_choice == computer_choice:
print("It's a tie!\n")
elif (player_choice == 1 and computer_choice == 3) or \
(player_choice == 2 and computer_choice == 1) or \
(player_choice == 3 and computer_choice == 2):
print("You win!\n")
else:
print("Computer wins!\n")

# Play again?
play_again = input("Play again? (y/n): ")
if play_again.lower() != "y":
break

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy