Skip to content

Instantly share code, notes, and snippets.

@ultramookie
Last active March 21, 2021 17:20
Show Gist options
  • Save ultramookie/6f81379db6ddb4c9b2cf269773910468 to your computer and use it in GitHub Desktop.
Save ultramookie/6f81379db6ddb4c9b2cf269773910468 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import random
def winner(user,states):
ai = random.choice(list(states))
print("\n")
if user == ai:
print("Tie!")
winner = 0
elif user == "r":
if ai == "s":
print("Rock beats scissors. You win!")
winner = 1
else:
print("Paper beats rock. You lose!")
winner = 2
elif user == "s":
if ai == "p":
print("Scissors cut paper. You win!")
winner = 1
else:
print("Rock smashes scissors. You lose!")
winner = 2
elif user == "p":
if ai == "r":
print("Paper beats rock. You win!")
winner = 1
else:
print("Scissors cut paper. You lose!")
winner = 2
print("\n")
return winner
def main():
states = {
"r": "rock",
"p": "paper",
"s": "scissors"
}
userScore=0
aiScore=0
print("Lets play Rock, Paper, Scissors!")
while True:
user = input("What will it be? [r]ock, [p]aper or [s]cissors? OR [q]uit > ")
user = user.strip()
if user == "q":
print(f"Final score: User: {userScore} AI: {aiScore}")
break
elif user in states:
who = winner(user,states)
if who == 1:
userScore = userScore+1
elif who == 2:
aiScore = aiScore+1
else:
print("Unknown input! Try again!")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment