Learn Python 3- Magic 8 Ball

Hi,

This is my first time using this forum, so sorry if I come across unprofessional. It is regarding the ‘Magic 8 ball’ on Control flow. https://www.codecademy.com/courses/learn-python-3/projects/python-magic-8-ball

On Step 13, the task explores the what if’s, and asks to create a code for when the variable ‘name’ is empty. I have tried implementing that point using a if statement.

if name == “”:
print("Question " + question)

else:
print(name + " asks: " + question)

However this just causes the code to be replicated again. I have posted a copy of my code, and would be eternally grateful for any help!

import random
random_number = random.randint(1, 10)
#prints out random numbers from 1-10

name =“Belle”

question = “Will I have a good day tomorrow?”

answer = “”

if random_number == 1:
answer = “Yes - definitley”

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 = “Most definitely”

else:
print(“Error”)

if name == “”:
print("Question " + question)

else:
print(name + " asks: " + question)

print(name + " asks: " + question)
print("Magic 8-Ball’s answer: " + answer)

check your last else: statement

your code is repeating because you have 2 prints hehe

1 Like

Oh ofc, how did I miss that, thanks so much!

np, happens to me all the time

import random
name - “Akeem”
question = “Do you like me?”
answer - “”

random_number = random.randiant(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" + question)
print("Magic 8-balls answer: " + answer)

keep getting error losing my mind