I was doing the magic 8 ball exercise, and for some reason, after I completed the code, and ran it. It did what it was suppost to do but out of order. I cant figure out why. Here is the code. It always yields the prediction before the question and I cant figure out why. The code seems to be line for line with the solution, but it yields slightly different results .
import random
name = “Joe”
question = (“will I win the lottery?”)
answer = “”
random_number = random.randint(1,9)
#print(random_number)
if random_number == 1:
print("Yes -definetly ")
elif random_number == 2:
print(“It is definetly so”)
elif random_number ==3:
print(“with out a doubt”)
elif random_number == 4:
print(“Reply hazy, try again”)
elif random_number == 5:
print(“Ask again later”)
elif random_number == 6:
print(“Better not tell you know”)
elif random_number == 7:
print (“My sources say no”)
elif random_number == 8:
print (“Outlook not so good”)
elif random_number == 9:
print(“Very doubtful”)
else:
answer = “Error”
print(name + " asks: " + question)
print("Magic 8 Ball’s answer: " + answer)