-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
69 lines (49 loc) · 1.83 KB
/
main.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import random
def get_user_choice():
choice = input("Enter your choice rock, paper,scissors ")
while choice!='rock' and choice !="paper" and choice!="scissors":
choice = input("Enter valid choice rock, paper,scissors ")
print("Your choice",choice)
return choice
def get_computer_choice():
computerChoice = random.choice(["rock" ,"paper","scissors"])
print("Computer Choice",computerChoice )
return computerChoice
def determine_winner(user_choice, computer_choice):
if user_choice == "rock" and computer_choice=="scissors" :
print("You Win!")
return "user"
elif user_choice=="rock" and computer_choice=="paper":
print("Computer Wins!")
return "computer"
elif user_choice == "scissors" and computer_choice=="rock" :
print("Computer Wins!")
return "computer"
elif user_choice == "scissors" and computer_choice == "paper":
print("You Win!")
return "user"
elif user_choice == "paper" and computer_choice == "scissors":
print("Computer Wins!")
return "computer"
elif user_choice == "paper" and computer_choice == "rock":
print("You Win!")
return "user"
else:
print("It's a tie!")
def rock_paper_scissors():
cWin = 0
uWin = 0
while True:
winner = determine_winner(get_user_choice() ,get_computer_choice())
if winner == "user":
uWin +=1
elif winner=="computer":
cWin +=1
anotherRound = input("Do You Want To Play Another Round ? yes or no ")
if anotherRound == "no":
print("user wins",uWin)
print("computer wins",cWin)
print("Program ends. Goodbye!")
break
rock_paper_scissors()
input("press enter to exit") # i added this since when i run it using the cmd it closes wihout printing the result