Turn on thread page Beta
    • Thread Starter
    Offline

    2
    ReputationRep:
    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!")
    Offline

    4
    ReputationRep:
    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
    Offline

    3
    ReputationRep:
    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
    • Thread Starter
    Offline

    2
    ReputationRep:
    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?
    Offline

    3
    ReputationRep:
    Attachment 696584
    Here you go
 
 
 
Reply
Submit reply
Turn on thread page Beta
Updated: October 17, 2017

University open days

  1. University of Bradford
    University-wide Postgraduate
    Wed, 25 Jul '18
  2. University of Buckingham
    Psychology Taster Tutorial Undergraduate
    Wed, 25 Jul '18
  3. Bournemouth University
    Clearing Campus Visit Undergraduate
    Wed, 1 Aug '18
Poll
How are you feeling in the run-up to Results Day 2018?

The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

Write a reply...
Reply
Hide
Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.