Skip to content

Commit 4807650

Browse files
authored
Add files via upload
Rock-Paper-Scissors game with even more options to choose, defining by user. I was doing it via JetBrains Academy.
1 parent 3135a7f commit 4807650

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

game.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import random
2+
name = input("Enter your name: ")
3+
print("Hello, " + name + "\n")
4+
score = 0
5+
ratings = open("rating.txt", "r")
6+
for line in ratings:
7+
if name == line.split()[0]:
8+
score = line.split()[1]
9+
else:
10+
score = 0
11+
12+
user_options = input()
13+
print("Okay, let's start")
14+
user_options_list = user_options.split(",")
15+
16+
if len(user_options_list) < 3:
17+
options = ["rock", "paper", "scissors"]
18+
else:
19+
options = user_options_list[::]
20+
21+
while True:
22+
user_input = input()
23+
if user_input == "!rating":
24+
print("Your rating: ", score)
25+
if user_input == "!exit":
26+
print("Bye!")
27+
break
28+
if user_input not in options:
29+
print("Invalid input")
30+
continue
31+
else:
32+
computer_choose = random.choice(options)
33+
user_index = options.index(user_input)
34+
center_index = len(options) // 2
35+
n = center_index - user_index
36+
list_centered = (options[-n:] + options[:-n])
37+
computer_index = list_centered.index(computer_choose)
38+
if computer_index == center_index:
39+
print("There is a draw " + computer_choose)
40+
score += 50
41+
elif computer_index < center_index:
42+
print("Well done. Computer chose " + computer_choose + " and failed")
43+
score += 100
44+
else:
45+
print("Sorry, but computer chose " + computer_choose)
46+
ratings.close()

0 commit comments

Comments
 (0)