Computer Science Python help?!!

Watch this thread
shatter1237
Badges: 2
Rep:
? You'll earn badges for being active around the site. Rep gems come when your posts are rated by other community members.
#1
Report Thread starter 4 years ago
#1
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!")
0
reply
lucylambert88
Badges: 4
Rep:
? You'll earn badges for being active around the site. Rep gems come when your posts are rated by other community members.
#2
Report 4 years ago
#2
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
0
reply
ben.foreman
Badges: 3
Rep:
? You'll earn badges for being active around the site. Rep gems come when your posts are rated by other community members.
#3
Report 4 years ago
#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 696576
0
reply
shatter1237
Badges: 2
Rep:
? You'll earn badges for being active around the site. Rep gems come when your posts are rated by other community members.
#4
Report Thread starter 4 years ago
#4
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 696576[/QUOTE]

Hello, Thanks for the reply but the attachment is unusually not working for me, can you please resend it?
0
reply
ben.foreman
Badges: 3
Rep:
? You'll earn badges for being active around the site. Rep gems come when your posts are rated by other community members.
#5
Report 4 years ago
#5
Attachment 696584
Here you go
0
reply
X

Quick Reply

Attached files
Write a reply...
Reply
new posts
Back
to top
Latest
My Feed

See more of what you like on
The Student Room

You can personalise what you see on TSR. Tell us a little about yourself to get started.

Personalise

How was the OCR A-level Geography Paper 1 exam for you?

Great! (9)
14.29%
Quite well (29)
46.03%
Not so good (16)
25.4%
Terrible! (9)
14.29%

Watched Threads

View All