My version of: Rock Paper Scissors

import random # 1 - rock # 2 - paper # 3 - scissors def doesPlayerWin(num, rnum): if num == 1 and rnum == 3: print("Rock beats Scissors... you win!!!") return 1 elif num == 2 and rnum == 1: print("Paper beats Rock... you win!!!") return 1 elif num == 3 and rnum == 2: print("Scissors beat Paper... you win!!!") return 1 elif rnum == 1 and num == 3: print("Rock beats Scissors... you loose!!!") return -1 elif rnum == 2 and num == 1: print("Paper beats Rock... you loose!!!") return -1 elif rnum == 3 and num == 2: print("Scissors beat Paper... you loose!!!") return -1 else: print("It is a draw!!!") return 0 wins = 0 loses = 0 draws = 0 while True: randomDraw = random.randrange(1, 4) entry = input("[R]ock/[P]aper/[S]cissors or [E]xit: ") entry.lower() if entry == "exit" or entry == "e": break elif entry == "rock" or entry == "r": entry = 1; elif entry == "paper" or entry == "p": entry = 2; elif entry == "scissors" or entry == "s": entry = 3; else: print("Wrong input!!!") continue result = doesPlayerWin(entry, randomDraw); if result == 1: wins += 1 elif result == -1: loses += 1 elif result == 0: draws += 1 print("Game ended!!! You have played {} times. {} times it was a draw. You have lost {} times, Won {} times".format(draws + wins + loses, draws, loses, wins))
Day 2 of learning python: Doing coding challenges

Is there a switch statement in Python?

Anyways, this is my version of Player vs AI R.P.S. The input is not case-sensitive

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.