Created
June 30, 2022 07:33
-
-
Save shahzaibkhan/a8bec34cb1d7e1f673e0e477a1d8df0d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# import the module you’ll use to simulate the computer’s choices: | |
import random | |
# take the user input | |
user_action = input("Enter a choice (rock, paper, scissors): ") | |
# Define the possible choices and let the computer choose one of them randomly | |
possible_actions = ["rock", "paper", "scissors"] | |
computer_action = random.choice(possible_actions) | |
print(f"\nYou chose {user_action}, computer chose {computer_action}.\n") | |
# Determine a Winner i.e. Implement the logic | |
if user_action == computer_action: | |
print(f"Both players selected {user_action}. It's a tie!") | |
elif user_action == 'rock': | |
if computer_action == "scissors": | |
print("Rock smashes scissors! You win!") | |
else: | |
print("Paper covers rock! You lose.") | |
elif user_action == "paper": | |
if computer_action == "rock": | |
print("Paper covers rock! You win!") | |
else: | |
print("Scissors cuts paper! You lose.") | |
elif user_action == "scissors": | |
if computer_action == "paper": | |
print("Scissors cuts paper! You win!") | |
else: | |
print("Rock smashes scissors! You lose.") | |
else: | |
print("Your choice doesnt exist, You loose") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment