Python 3- Magic 8-Ball exercise

Hi
I have tried and tried and coming up with no idea where im going wrong. But on the magic 8-ball exercise i have encountered a syntax error on line 30 of my code thats says its invalid syntax, however im struggling to see where ive gone wrong, if anyone could help me out, it might be something or simple and straightforward to fix, but im getting frustrated. Here is the code-

import random
name = "Dave"
question = "Yes" or "No"
answer= ""

random_number = random.randint(1, 9)


if random_number == 1:
  answer = "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." 
else: 
  answer = "Error"

print(name + "asks: " + Will i learn python?)
print("Magic 8-Ball's answer: " + answer)




  

The last part of that expression should be str, should it not?

This line could also be a problem, unless you’re using it as a placeholder, because question will be a boolean value that evaluates to True, because since strings are only false when they are blank strings (""), question is basically equal to True or True, which is True. So keep that in mind if you’re going to use the question variable

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.