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