-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrock-paper-scissors.py
40 lines (36 loc) · 1.06 KB
/
rock-paper-scissors.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
import random
name = input('Enter your name: ')
print(f'Hello, {name}')
score = 0
with open('rating.txt') as file:
for line in file:
player_name, player_score = line.split()
if name == player_name:
score = int(player_score)
break
options = input().split(',')
if options == ['']:
options = ['rock', 'paper', 'scissors']
print("Okay, let's start")
while True:
player = input()
if player == '!exit':
print('Bye')
break
if player == '!rating':
print(f'Your rating: {score}')
continue
if player not in options:
print('Invalid input')
continue
computer = random.choice(options)
if computer == player:
score += 50
print(f'There is a draw ({computer})')
else:
offset = (options.index(computer) - options.index(player)) % len(options)
if offset > len(options) // 2:
score += 100
print(f'Well done. Computer chose {computer} and failed')
else:
print(f'Sorry, but computer chose {computer}')