From 683e2583437c8c94c64496286cbb629616878367 Mon Sep 17 00:00:00 2001 From: Peyman Daei Rezaei <88220773+Peyman2012@users.noreply.github.com> Date: Wed, 18 May 2022 01:30:49 +0430 Subject: [PATCH] Update Rock-paper-scissor.md def get_winner(p1, p2): if p1 == p2: return "It's a tie!" elif p1 == 'rock': if p2 == 'scissors': return "First player wins!" else: return "Second Player wins!" elif p1 == 'scissors': if p2 == 'paper': return "First player win!" else: return"Second player wins!" elif p1 == 'paper': if p2 == 'rock': return "First player wins!" else: return "Second player win!" else: return "Invalid input!" loop=True while loop: player1 = input("First player: rock, paper or scissors: ") player2 = input("Second Player: rock, paper or scissors: ") if player1=='E' or player2=='e': loop= False print(get_winner(player1, player2)) --- Simple-Game/Rock-paper-scissor.md | 32 ++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/Simple-Game/Rock-paper-scissor.md b/Simple-Game/Rock-paper-scissor.md index 45a2726..ea5a806 100644 --- a/Simple-Game/Rock-paper-scissor.md +++ b/Simple-Game/Rock-paper-scissor.md @@ -40,6 +40,36 @@ player2 = input("Second Player: rock, paper or scissors: ") print(get_winner(player1, player2)) ``` + +def get_winner(p1, p2): + if p1 == p2: + return "It's a tie!" + + elif p1 == 'rock': + if p2 == 'scissors': + return "First player wins!" + else: + return "Second Player wins!" + elif p1 == 'scissors': + if p2 == 'paper': + return "First player win!" + else: + return"Second player wins!" + elif p1 == 'paper': + if p2 == 'rock': + return "First player wins!" + else: + return "Second player win!" + else: + return "Invalid input!" +loop=True +while loop: + player1 = input("First player: rock, paper or scissors: ") + player2 = input("Second Player: rock, paper or scissors: ") + if player1=='E' or player2=='e': + loop= False + print(get_winner(player1, player2)) + **[Try it on Programming Hero](https://play.google.com/store/apps/details?id=com.learnprogramming.codecamp)** ## Explanation @@ -59,4 +89,4 @@ If you find a way, add a question here so that everyone can see your code. [](Cows-and-bulls.md) -tags: `programming-hero` `python` `python3` `problem-solving` `programming` `coding-challenge` `interview` `learn-python` `python-tutorial` `programming-exercises` `programming-challenges` `programming-fundamentals` `programming-contest` `python-coding-challenges` `python-problem-solving` \ No newline at end of file +tags: `programming-hero` `python` `python3` `problem-solving` `programming` `coding-challenge` `interview` `learn-python` `python-tutorial` `programming-exercises` `programming-challenges` `programming-fundamentals` `programming-contest` `python-coding-challenges` `python-problem-solving`