Jump to content

Coding

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Hsusah (talk | contribs) at 04:12, 2 March 2025 (Other uses: Game). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Coding may refer to:

Computer science

Other uses

def game():

   while True:
       user_choice = input("Enter your choice (rock/paper/scissors): ")
       user_choice = user_choice.lower()
       while user_choice not in ["rock", "paper", "scissors"]:
           user_choice = input("Invalid input. Enter your choice (rock/paper/scissors): ")
           user_choice = user_choice.lower()
       computer_choice = random.choice(["rock", "paper", "scissors"])
       print(f"\nUser chose {user_choice}, computer chose {computer_choice}.\n")
       if user_choice == computer_choice:
           print(f"Both players selected {user_choice}. It's a tie!")
       elif user_choice == "rock":
           if computer_choice == "scissors":
               print("Rock smashes scissors! You win!")
           else:
               print("Paper covers rock! You lose.")
       elif user_choice == "paper":
           if computer_choice == "rock":
               print("Paper covers rock! You win!")
           else:
               print("Scissors cuts paper! You lose.")
       elif user_choice == "scissors":
           if computer_choice == "paper":
               print("Scissors cuts paper! You win!")
           else:
               print("Rock smashes scissors! You lose.")
       play_again = input("Play again? (yes/no): ")
       if play_again.lower() != "yes":
           break

game()

See also