Skip to content

Instantly share code, notes, and snippets.

@amankharwal
Created January 16, 2021 11:43
Show Gist options
  • Save amankharwal/e904347ed8fdb8ffc276cda78d7c9c8a to your computer and use it in GitHub Desktop.
Save amankharwal/e904347ed8fdb8ffc276cda78d7c9c8a to your computer and use it in GitHub Desktop.
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
@PJ-VM
Copy link

PJ-VM commented Nov 10, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment