Facebook
From Hrishikesh Saha, 1 Year ago, written in Python.
Embed
Download Paste or View Raw
Hits: 105
  1. import random
  2.  
  3. while True:
  4.     name = input("Enter your name:")
  5.     enter = input("Enter your choice (rock/paper/scissors/):")
  6.     actions = ["rock","paper","scissors"]
  7.     computer = random.choice(actions)
  8.     score = 0
  9.     score2 = 0
  10.     print(f"You chose {enter}, computer chose {computer}")
  11.     print()
  12.  
  13.     if computer == enter:
  14.         print("Both selected same. Its tie.")
  15.     elif computer == "rock":
  16.         if enter == "paper":
  17.             print(f"Paper covers rock. {name} win.")
  18.             score+=1
  19.         elif enter == "scissors":
  20.             print("Rock breaks scissors. Computer wins.")
  21.             score2+=1
  22.     elif computer == "paper":
  23.         if enter == "rock":
  24.             print("Paper covers rock. Computer wins.")
  25.             score2+=1
  26.         elif enter == "scissors":
  27.             print(f"Scissor cuts paper. {name} win.")
  28.             score+=1
  29.     elif computer == "scissors":
  30.         if enter == "rock":
  31.             print(f"Rock breaks scissors. {name} win.")
  32.             score+=1
  33.         elif enter == "paper":
  34.             print("Scissor cuts paper. computer wins.")
  35.             score2+=1
  36.  
  37.     print()
  38.     again = input("Play again? (y/n):")
  39.     if again == "y":
  40.         continue
  41.     elif again == "n":
  42.         print(f"Computer = {score2}")
  43.         print(f"{name} = {score}")
  44.         break