Hi all,
I have what might be a simple question relating to the optional challenges of the Magic-8Ball project in the Python 3 course.
Initially, the directions ask the coder to hardcode string assigned to the variable ‘name’. However, in challenge 13, the directions bring up a hypothetical situation in which the user does not provide their name. My assumption is that I am supposed to reassign ‘name’ to a user input. When I try to create a user input, an error shows up when running the program.
The lesson environment for this project only has an output console not a full functioning terminal, so you cannot get user input. Since it isn’t possible for a user to enter input, the EOFError
is thrown. You could run your code on your own computer or in an environment like replit.com if you want to be able to get user input.
1 Like
Thank you for your input and recommendation. I was afraid that this would be the reason for the error. The directions here are a little misleading
1 Like
For steps 13 and 14, no name or no question, writing in the code to generate or print the desired outcome was pretty easy; however, after writing the no question portion I had TWO answers generated… one random 8ball phrase (despite no question input in the question variable: question = “”) and then the 8ball response in the scenario where no question was provided, “The Magic 8-Ball cannot provide a fortune unless you ask it something.”. I’m no programmer but I know what I wanted – I wanted to have just a ONE line printed for the user and ONE line printed for the 8ball. I used only the tools in the lessons (I used not statements) up until this point and came up with the following solution:
import random
name = “”
question = “”
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”
if name == “”:
print ("Question: " + question)
if not name == “”:
print (name + " asks: " + question)
if question == “”:
print (“The Magic 8-Ball cannot provide a fortune unless you ask it something.”)
if not question == “”:
print("Magic 8-Ball’s answer: " + answer)