Hey there! Sign in to join this conversationNew here? Join for free
    • 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

    1
    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

    1
    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

    1
    ReputationRep:
    Attachment 696584
    Here you go
 
 
 
  • 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.

  • Poll
    What newspaper do you read/prefer?
  • 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.

  • 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

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