jimMoonrock

Scissors_Rock_paper

Apr 26th, 2021
1,090
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.37 KB | None | 0 0
  1. import random
  2.  
  3.  
  4. with open("rating.txt", encoding="utf-8") as file:
  5.     data_players, user_count = {}, 0
  6.  
  7.     for name_and_score in file.readlines():
  8.         data = name_and_score.strip('\n').split(" ")
  9.         data_players[data[0]] = int(data[1])
  10.  
  11. user_name = input("Enter your name: ")
  12. print(f"Hello, {user_name}")
  13.  
  14. while True:
  15.     user_try = random.randint(0, 3)
  16.     computer = random.randint(0, 3)
  17.  
  18.     inp = input( )
  19.     if inp in ["rock", "paper", "scissors"]:
  20.  
  21.         if user_try > computer:
  22.             if user_name in data_players:
  23.                 if inp == "rock":
  24.                     print("Well done. The computer chose scissors and failed")
  25.                     data_players[user_name] += 100
  26.                 elif inp == "scissors":
  27.                     print("Well done. The computer chose paper and failed")
  28.                     data_players[user_name] += 100
  29.                 elif inp == "paper":
  30.                     print("Well done. The computer chose rock and failed")
  31.                     data_players[user_name] += 100
  32.             else:
  33.                 if inp == "rock":
  34.                     print("Well done. The computer chose scissors and failed")
  35.                     user_count += 100
  36.                 elif inp == "scissors":
  37.                     print("Well done. The computer chose paper and failed")
  38.                     user_count += 100
  39.                 elif inp == "paper":
  40.                     print("Well done. The computer chose rock and failed")
  41.                     user_count += 100
  42.         elif user_try < computer:
  43.             if inp == "rock":
  44.                 print("Sorry, but the computer chose paper")
  45.             elif inp == "scissors":
  46.                 print("Sorry, but the computer chose rock")
  47.             elif inp == "paper":
  48.                 print("Sorry, but the computer chose scissors")
  49.                
  50.  
  51.         elif user_try == computer:
  52.             if user_name in data_players:
  53.                 data_players[user_name] += 50
  54.             else:
  55.                 user_count += 50
  56.             print(f"There is a draw ({inp})")
  57.  
  58.     elif inp == "!rating":
  59.         if user_name in data_players:
  60.             print(f"Your rating: {data_players[user_name]}")
  61.         else:
  62.             print(f"Your rating: {user_count}")
  63.  
  64.  
  65.     elif inp == "!exit":
  66.         print("Bye!")
  67.         break
  68.     else:
  69.         print("Invalid input")
  70.  
Advertisement
Add Comment
Please, Sign In to add comment