-
-
Save amankharwal/e904347ed8fdb8ffc276cda78d7c9c8a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
choices = ["Rock", "Paper", "Scissors"] | |
computer = random.choice(choices) | |
player = False | |
cpu_score = 0 | |
player_score = 0 | |
while True: | |
player = input("Rock, Paper or Scissors?").capitalize() | |
## Conditions of Rock,Paper and Scissors | |
if player == computer: | |
print("Tie!") | |
elif player == "Rock": | |
if computer == "Paper": | |
print("You lose!", computer, "covers", player) | |
cpu_score+=1 | |
else: | |
print("You win!", player, "smashes", computer) | |
player_score+=1 | |
elif player == "Paper": | |
if computer == "Scissors": | |
print("You lose!", computer, "cut", player) | |
cpu_score+=1 | |
else: | |
print("You win!", player, "covers", computer) | |
player_score+=1 | |
elif player == "Scissors": | |
if computer == "Rock": | |
print("You lose...", computer, "smashes", player) | |
cpu_score+=1 | |
else: | |
print("You win!", player, "cut", computer) | |
player_score+=1 | |
elif player=='End': | |
print("Final Scores:") | |
print(f"CPU:{cpu_score}") | |
print(f"Plaer:{player_score}") | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey, I'm brand new to this; literally day 2 learning on w3. I ran into a challenge with the code where the computer's choice remained consistent throughout the 'game'. I did a bit of research and apparently its because the "computer = random.choice(choices)" happens outside the 'while' loop. Hope this is beneficial, thanks.