Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Rock-paper-scissor.md #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
  • Loading branch information
Peyman2012 authored May 17, 2022
commit 683e2583437c8c94c64496286cbb629616878367
32 changes: 31 additions & 1 deletion Simple-Game/Rock-paper-scissor.md
Original file line number Diff line number Diff line change
@@ -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.
[![Next Page](../assets/next-button.png)](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`
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`