Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- class rock_Paper_Scissors:
- def __init__(self, choice):
- self.choice = choice
- if self.choice == "I want to play":
- return self.main_func()
- def main_func(self):
- 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}")
- return self.func_with_game(user_name, data_players, user_count)
- def func_with_game(self, name, database_with_players,sum_of_of_person_out_db):
- self.name = name
- self.database_with_players = database_with_players
- self.sum_of_of_person_out_db = sum_of_of_person_out_db
- 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 name in database_with_players:
- if inp == "rock":
- print("Well done. The computer chose scissors and failed")
- database_with_players[name] += 100
- elif inp == "scissors":
- print("Well done. The computer chose paper and failed")
- database_with_players[name] += 100
- elif inp == "paper":
- print("Well done. The computer chose rock and failed")
- database_with_players[name] += 100
- else:
- if inp == "rock":
- print("Well done. The computer chose scissors and failed")
- sum_of_of_person_out_db += 100
- elif inp == "scissors":
- print("Well done. The computer chose paper and failed")
- sum_of_of_person_out_db += 100
- elif inp == "paper":
- print("Well done. The computer chose rock and failed")
- sum_of_of_person_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 name in database_with_players:
- database_with_players[name] += 50
- else:
- sum_of_of_person_out_db += 50
- print(f"There is a draw ({inp})")
- elif inp == "!rating":
- if name in database_with_players:
- print(f"Your rating: {database_with_players[name]}")
- else:
- print(f"Your rating: {sum_of_of_person_out_db}")
- elif inp == "!exit":
- print("Bye!")
- break
- else:
- print("Invalid input")
- ron = rock_Paper_Scissors("I want to play")
Advertisement
Add Comment
Please, Sign In to add comment