import random print("Ask the Magic Python Ball a question:") question = input()…
- User
import random
print("Ask the Magic Python Ball a question:") question = input() print("") print("Loading...") num = random.randint(1,13) if num == 1: print("") print("Magic Python Ball: Ask again later, I'm not gonna answer your stupid question.") elif num == 2: print("") print("Magic Python Ball: I'm not going to answer just to be petty. ") elif num == 3: print("") print("Magic Python Ball: Totally not, bro.") elif num == 4: print("") print("Magic Python Ball: Nah") elif num == 5: print("") print("Magic Python Ball: IDK") elif num == 6: print("") print("Magic Python Ball: Yuh") elif num == 7: print("") print("Magic Python Ball: Nuh uh") elif num == 8: print("") print("Magic Python Ball: I uhhhh") elif num == 9: print("") print("Magic Python Ball: Sureeeee") elif num == 10: print("") print("Magic Python Ball: YOU can solve this question.") elif num == 11: print("") print("Magic Python Ball: You can take a guess on this one.") elif num == 12: print("") print("Magic Python Ball: Believe whatever you want.") elif num == 13: print("") print("Magic Python Ball: Error Code: 2904 (This is a real Error Code and isn't me trying to avoid your question.)") I want this to loop back to the beginning after a question is answered.
- Assistant
You can achieve the desired looping behavior by enclosing the logic inside a while loop. Here's an updated version of the code:
import random while True: print("Ask the Magic Python Ball a question:") question = input() print("") print("Loading...") num = random.randint(1,13) if num == 1: print("") print("Magic Python Ball: Ask again later, I'm not gonna answer your stupid question.") elif num == 2: print("") print("Magic Python Ball: I'm not going to answer just to be petty. ") elif num == 3: print("") print("Magic Python Ball: Totally not, bro.") elif num == 4: print("") print("Magic Python Ball: Nah") elif num == 5: print("") print("Magic Python Ball: IDK") elif num == 6: print("") print("Magic Python Ball: Yuh") elif num == 7: print("") print("Magic Python Ball: Nuh uh") elif num == 8: print("") print("Magic Python Ball: I uhhhh") elif num == 9: print("") print("Magic Python Ball: Sureeeee") elif num == 10: print("") print("Magic Python Ball: YOU can solve this question.") elif num == 11: print("") print("Magic Python Ball: You can take a guess on this one.") elif num == 12: print("") print("Magic Python Ball: Believe whatever you want.") elif num == 13: print("") print("Magic Python Ball: Error Code: 2904 (This is a real Error Code and isn't me trying to avoid your question.)") print("Ask another question? (Y/N)") answer = input() if answer.upper() != "Y": break print("")