The Student Room Group

Computer Science Python help?!!

I have to randomly generate rock paper scissors until it matches with the string typed in but it doesn't run the program which means something is wrong with the code can you help, please?
import random
rps = [rock,paper,scissors]
pchoice =input("rock, paper, scissors?")
cchoice = random.choice(rps)
print("The computer has chosen",cchoice,"!")
if pchoice == cchoice:
print("Snap!")
elif pchoice == "rock" and cchoice =="paper":
print("You lose")
elif pchoice == "paper" and cchoice == "scissors":
print("You lose")
elif pchoice =="scissors" and cchoice == "rock":
print("You lose")
else:
print("you win!")
you might need to abandon the square brackets for the random, try having the program pick a random number between 1 and 3, then rock is assigned 1, paper is assigned 2 and scissors is assigned 3 (put this section before the if/else selection section. i hope it works, if not then ask a teacher or a classmate and im sure they would try to help :smile:
Hi, there are several reasons why your code didn't work: 1. Your commands within the IF statements weren't indented2. You had not called nor named the program3. The items in the array 'rps' were not in speech marksI have corrected these errors for you, I hope this helps
Attachment not found
(edited 6 years ago)
Reply 3
Hi, there are several reasons why your code didn't work: 1. Your commands within the IF statements weren't indented2. You had not called nor named the program3. The items in the array 'rps' were not in speech marksI have corrected these errors for you, I hope this helps
Attachment not found


Hello, Thanks for the reply but the attachment is unusually not working for me, can you please resend it?
Attachment not found

Here you go :smile:
(edited 6 years ago)

Quick Reply