Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Why do i get a syntax error when importing random?

+5 votes
asked Apr 27, 2022 by Matthew Anderson (170 points)
This is my code:

https://onlinegdb.com/VgxGtx4Xq

i get syntax error with the import random, please heelp

3 Answers

0 votes
answered Apr 28, 2022 by Peter Minarik (86,040 points)
  1. You are missing a closing parenthesis from the end of your first line
  2. Line 5 should have the same indentation (i.e., none) as the other lines around it.
  3. Your line 5 logic doesn't make sense to me in regards for the rules of the rock-paper-scissor game. More importantly, your trying to set the value of win to win + a random value, but at this point, win (on the right side) is not defined so your code makes no sense to the compiler. Please, review your logic.
0 votes
answered Apr 29, 2022 by userdotexe (1,340 points)
edited May 26, 2022 by userdotexe

I fixed your code: https://onlinegdb.com/wLkBVepCm

Edit: You have one little mistake...

length = (input("Please enter rock, paper, or scissors.  ") # Delete the first '('

import random
things = "rock","paper", "scissors"
win = win + random.choice(things) # No indentation is necessary here
print(win)

:)

+1 vote
answered Apr 29, 2022 by mohd ashiq (160 points)
length =input("Please enter rock, paper, or scissors.  ")

import random
things = ["rock","paper", "scissors"]
win = random.choice(things)
print(win)
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...