'I get an unexpected EOF while parsing error on my magic 8 ball code
I am trying to code a magic eight ball on the sololearn code playgroud using python. I used a while loop and I guess its not closing? I tried to use break, return and endloop at the end and in the middle of the code but still gave me the error. For the sake of the question i deleted the break/return/endloop and leaved it blank for help. Here is the full code:
import random
responses = [
"It is certain",
"Without a doubt",
"You may rely on it",
"Yes definitely",
"It is decidedly so",
"As I see it, yes",
"Most likely",
"Yes",
"Outlook good",
"Signs point to yes",
"Reply hazy try again",
"Better not tell you now",
"Ask again later",
"Cannot predict now",
"Concentrate and ask again",
"Don't count on it",
"Outlook not so good",
"My sources say no",
"Very doubtful",
"My reply is no"
]
while True:
try:
question = str(input("Doesthiswork"))
endloop
if "meaning of life" in question:
print("The Magic 8 Ball says: 42")
else:
print("The Magic 8 Ball says: {answer}")
Solution 1:[1]
Welcome to Stack Overflow! The issue here is you have a bare try clause, with no matching except. The solution is to add an except clause or delete the try and adjust the indentation.
i.e.
try:
code("hi")
except ValueError: # if you have "try:" you need an "except"
print("oops")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Seth |
