-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
142 lines (123 loc) · 5.36 KB
/
Copy pathmain.py
File metadata and controls
142 lines (123 loc) · 5.36 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
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import random
import time
# Explains the game rules and options to the user
rps_game_info = """Welcome to Rock Paper Scissors Game
Rules:
You can choose one of the following options:
- rock
- paper
- scissors
* Rock beats scissors
* Scissors beats paper
* Paper beats rock
It is a tie if you and the computer choose the same option.
Game:
You will be playing against the computer.
You will be playing until one of you wins 2 times in one game.
If you want to play again, you can type 'yes'.
If you want to exit the game, you can type 'exit'.\n\n"""
print(rps_game_info)
rps_game_options = ['rock', 'paper', 'scissors']
game_continue = ['yes', 'no']
# Function to get the user's choice and the computer's choice
def _choice_():
# This will be used to determine whether game is on or not
game = True
# taking user's choice
user_choice = input("\nEnter your choice of " +
"'rock', 'paper', 'scissors' or 'exit' : ")
while True:
# If user wants to exit the game
if user_choice == "exit":
game = False
break
# If user's choice is one of the game options
elif user_choice in rps_game_options:
break
# If user enters an invalid choice
else:
print("Invalid choice. Please try again.")
user_choice = input("\nEnter your choice of " +
"'rock', 'paper', 'scissors' or 'exit' : ")
# User exits the game
if not game:
print("\nGame is over.")
# Computer's choice
computer_choice = random.choice(rps_game_options)
print("\nMy choice: " + computer_choice)
return user_choice, computer_choice, game
# Function to play the game
def tas_kagit_makas_BERFUDENIZ_KARA():
# Initialising the total wins of user and computer
user_total_win = 0
computer_total_win = 0
# Taking the user's choice and the computer's choice
user_choice, computer_choice, game = _choice_()
# Game loop
while game:
# Rounds loop until one of the players win 2 rounds in total
while (user_total_win < 2 and
computer_total_win < 2):
# Tie
if user_choice == computer_choice:
print("\nIt is a tie! What a waste of time... Score: You: " ,
user_total_win , " Me: " , computer_total_win)
# User wins, user = rock, computer = scissors
elif (user_choice == "rock" and
computer_choice == "scissors"):
user_total_win += 1
print("\nYou win :( Score: You: " , user_total_win ,
" Me: " , computer_total_win)
# User wins, user = paper, computer = rock
elif (user_choice == 'paper' and
computer_choice == "rock"):
user_total_win += 1
print("\nYou win :( Score: You: " , user_total_win ,
" Me: " , computer_total_win)
# User wins, user = scissors, computer = paper
elif (user_choice == 'scissors' and
computer_choice == "paper"):
user_total_win += 1
print("\nYou win :( Score: You: " , user_total_win ,
" Me: " , computer_total_win)
# Computer wins, other options
else:
computer_total_win += 1
print("\nHa Ha!! You loser! Score: You: " , user_total_win ,
" Me: " , computer_total_win)
# If the game is not over, take the user's choice and the computer's choice again
if (user_total_win < 2 and
computer_total_win < 2):
user_choice, computer_choice, game = _choice_()
# If the game is over
print("\nGame is finished.")
print("Final Score: You: " , user_total_win ,
" Me: " , computer_total_win)
# Total win count is reset for the new game
user_total_win = 0
computer_total_win = 0
# Asking user and computer if they want to play again or not
while True:
play_again = input("\nDo you want to play again? (yes/no): ")
# If user wants to play again
if play_again == "yes":
print("Great! Let me think...")
time.sleep(3)
# If computer wants to play again
if random.choice(game_continue) == "yes":
print("Okay, let's play again! I feel lucky :)")
break
# If computer doesn't want to play again
else:
print("Naah, maybe another time!")
game = False
break
# If user doesn't want to play again
elif play_again == "no":
print("Thanks for playing. See you!")
game = False
break
# If user enters an invalid choice
else:
print("Invalid choice. Please try again.")
tas_kagit_makas_BERFUDENIZ_KARA()