Hey all! (Please be gentle with me, I’m on day two of learning :3)
I’m stuck on the Magic 8-Ball project - I think I don’t fully understand how it works. I understand how if/elif/else work in theory but I’m stuck on actually running it practically
I’ve inputted the code exactly as it said I should:
import random name = "Dave" question = "Will I learn Python?" answer = "" random_number = random.randint(1, 9) # print(random_number) if random_number == 1: print("Yes - definitely!") elif random_number == 2: print("It is decidedly so") elif random_number ==3: print("without 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 now..") 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: print("404 error") print(name + " asks: " + question) print("Magic 8-ball's answer: " + answer)
When I print I’m seeing it like this:
without a doubt.
Dave asks: Will I learn Python? Magic 8-ball's answer:
The answer is coming before and I’m not sure what I’m doing wrong? I’ve checked the solution that is isted and it looks exactly like mine (clearly not - but I don’t know what I’m missing.)
What I don’t understand is how it would print the answer correctly like this in the first place when the answer variable is an empty string - I understand why it prints it blank based on that logic. I’ve tried a few different things but I either get a syntax error or a type error from where I’ve tried to amend the value of the answer variable.
Any help would be greatly appreciated!