Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- with open("rating.txt", encoding="utf-8") as file:
- data_players, user_count = {}, 0
- for name_and_score in file.readlines():
- data = name_and_score.strip('\n').split(" ")
- data_players[data[0]] = int(data[1])
- user_name = input("Enter your name: ")
- print(f"Hello, {user_name}")
- while True:
- user_try = random.randint(0, 3)
- computer = random.randint(0, 3)
- inp = input( )
- if inp in ["rock", "paper", "scissors"]:
- if user_try > computer:
- if user_name in data_players:
- if inp == "rock":
- print("Well done. The computer chose scissors and failed")
- data_players[user_name] += 100
- elif inp == "scissors":
- print("Well done. The computer chose paper and failed")
- data_players[user_name] += 100
- elif inp == "paper":
- print("Well done. The computer chose rock and failed")
- data_players[user_name] += 100
- else:
- if inp == "rock":
- print("Well done. The computer chose scissors and failed")
- user_count += 100
- elif inp == "scissors":
- print("Well done. The computer chose paper and failed")
- user_count += 100
- elif inp == "paper":
- print("Well done. The computer chose rock and failed")
- user_count += 100
- elif user_try < computer:
- if inp == "rock":
- print("Sorry, but the computer chose paper")
- elif inp == "scissors":
- print("Sorry, but the computer chose rock")
- elif inp == "paper":
- print("Sorry, but the computer chose scissors")
- elif user_try == computer:
- if user_name in data_players:
- data_players[user_name] += 50
- else:
- user_count += 50
- print(f"There is a draw ({inp})")
- elif inp == "!rating":
- if user_name in data_players:
- print(f"Your rating: {data_players[user_name]}")
- else:
- print(f"Your rating: {user_count}")
- elif inp == "!exit":
- print("Bye!")
- break
- else:
- print("Invalid input")
Advertisement
Add Comment
Please, Sign In to add comment