-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram-8.py
More file actions
32 lines (28 loc) · 1.15 KB
/
Program-8.py
File metadata and controls
32 lines (28 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Write a program to make a two-player Rock-Paper-Scissors game. (Hint: Ask for player plays (using input), compare them, print out a message of congratulations to the winner, and ask if the players want to start a new game) Rules: Rock beats scissors, Scissors beats paper, Paper beats rock
import sys
user1 = input("What's your name?\n")
user2 = input("And your name?\n")
user1_answer = input("%s, do yo want to choose rock, paper or scissors?\n" % user1)
user2_answer = input("%s, do you want to choose rock, paper or scissors?\n" % user2)
def compare(u1, u2):
if u1 == u2:
return("It's a tie!")
elif u1 == 'rock':
if u2 == 'scissors':
return("Rock wins!")
else:
return("Paper wins!")
elif u1 == 'scissors':
if u2 == 'paper':
return("Scissors win!")
else:
return("Rock wins!")
elif u1 == 'paper':
if u2 == 'rock':
return("Paper wins!")
else:
return("Scissors win!")
else:
return("Invalid input! You have not entered rock, paper or scissors, try again.")
sys.exit()
print(compare(user1_answer, user2_answer))