Can someone please help me with the error of this code?

Hi guys, Danny here from the Netherlands.

i just started learning python, and its a lot of fun, but i’m stuck right now.

i hope someone can tell me what i am doing wrong.

for learning python i had to make a code for a magic 8 ball, evrything went well, until i reached the point
that i wanted to include a empty string.
that if the string was empty, the code gaved me another sentence, but at this point i got a syntax error, and i dont know why.

please be kind, its my 4th day with python.

thanks for your time .

greets danny

here is the code: the last line gives me the syntax error

name = (“danny”)
question = “will this work?”
answer = “”
import random
random_number = random.randint (1 ,15)
print (random_number)
if random_number == 1:
print(“Yes-definitely.”)
elif random_number == 2:
answer = “It is decidedly so”
elif random_number == 3:
answer = “Without a doubt”
elif random_number == 4 :
answer = “Reply hazy, try again.”
elif random_number == 5 :
answer = “Ask again later.”
elif random_number == 6 :
answer = “Better not tell you now.”
elif random_number == 7 :
answer = “My sources say no.”
elif random_number == 8 :
answer = “Outlook not so good.”
elif random_number == 9 :
answer = “Very doubtful.”
elif random_number == 10 :
answer = “nummertje tien”
elif random_number == 11 :
answer = “nummertje 11”
elif random_number == 12 :
answer = “nummer 12”
elif random_number == 13 :
answer = “dertien”
elif random_number == 14 :
answer = “probeersel 14”
elif random_number == 15 :
answer = “allerlaatste”
else:
answer = “Error”
print(name + " asks: "+ question)
print("Magic 8-Ball’s answer: " + answer)
if len(name) == 0

When you ask a question, don’t forget to include a link to the exercise or project you’re dealing with!

If you want to have the best chances of getting a useful answer quickly, make sure you follow our guidelines about how to ask a good question. That way you’ll be helping everyone – helping people to answer your question and helping others who are stuck to find the question and answer! :slight_smile:

The if statement should have : at the end.

1 Like

Sometimes it helps to read the code from the bottom up when you’re debugging. It forces you to read/interpret it differently.

1 Like

thankyou for you guys willing to help me.

im blessed.

greets danny

1 Like