198k views
3 votes
PLZ HELP!!! I'm a beginner in coding!

BTW, I'm a beginner in coding, so you don't have to get all fancy and stuff lol. Plz keep it "beginner's level" haha thx

1. Randomly choose rock, paper, or scissors for the computer
2. Ask the user to choose rock, paper, or scissors
3. Compare the computer’s choice to the player’s choice
4. Announce whether the computer or the human won

BUT!!! I already did 1, 2, and 3. I just need help with 4, how do I announce whether the computer or the human won? Am I suppose to use an if, elif, or else statement? Or a loop maybe? Please help! Thank you! Also, plz keep it simple, I just started learning coding

1 Answer

7 votes

import random

rock,paper,scissors = 1,2,3

choice = int(input("Please choose 1 2 or 3: "))

computer = random.randint(1,3)

player_won = False

draw = False

if choice == computer:

draw = True

elif choice == 1 and computer == 3:

player_won = True

elif choice == 2 and computer == 1:

player_won = True

elif choice == 3 and computer == 2:

player_won = True

if player_won:

print("You won!")

elif not player_won and not draw:

print("The computer won!")

else:

print("It's a draw!")

First, I recommend importing at the beginning of your program. Also, you can combine all your same datatype variables in one line. You also need to cast your user choice to an integer so you can compare it with the computer's choice. I wrote the if, elif, and else statements using a boolean variable. I simply wrote all the possibilities that would result in the player winning and this would result in the player_won variable being true. If this is the case, we print to the console, "You won!"

User Chris Arndt
by
5.2k points