Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- class RockPaperScissors:
- def __init__(self):
- self.choice = "No"
- self.name = ""
- self.users_in_database = {}
- self.user_count = 0
- self.count_for_person_who_out_db = 0
- def user_choice(self, choice):
- self.choice = choice
- if self.choice == "I want to play":
- return self.main_func()
- return self.exit_func()
- def main_func(self):
- with open("rating.txt", encoding="utf-8") as file:
- for name_and_score in file.readlines():
- data = name_and_score.strip('\n').split(" ")
- self.users_in_database[data[0]] = int(data[1])
- return self.func_with_game()
- def exit_func(self):
- return "Maybe, next time!"
- def func_with_game(self):
- self.name = input("Enter your name: ")
- print(f"Hello, {self.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 self.name in self.users_in_database:
- if inp == "rock":
- print("Well done. The computer chose scissors and failed")
- self.users_in_database[self.name] += 100
- elif inp == "scissors":
- print("Well done. The computer chose paper and failed")
- self.users_in_database[self.name] += 100
- elif inp == "paper":
- print("Well done. The computer chose rock and failed")
- self.users_in_database[self.name] += 100
- else:
- if inp == "rock":
- print("Well done. The computer chose scissors and failed")
- self.count_for_person_who_out_db += 100
- elif inp == "scissors":
- print("Well done. The computer chose paper and failed")
- self.count_for_person_who_out_db += 100
- elif inp == "paper":
- print("Well done. The computer chose rock and failed")
- self.count_for_person_who_out_db += 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 self.name in self.users_in_database:
- self.users_in_database[self.name] += 50
- else:
- self.count_for_person_who_out_db += 50
- print(f"There is a draw ({inp})")
- elif inp == "!rating":
- if self.name in self.users_in_database:
- print(f"Your rating: {self.users_in_database[self.name]}")
- else:
- print(f"Your rating: {self.count_for_person_who_out_db}")
- elif inp == "!exit":
- print("Bye!")
- break
- else:
- print("Invalid input")
- ron = RockPaperScissors()
- print(ron.user_choice("I want to play"))
Advertisement
Add Comment
Please, Sign In to add comment