🔮
Magic 8-Ball
Ask a question and let Python pick a random fortune.
Sprout· ages 8–1010 minimportrandom.choicelists
fortune.py
…First load pulls ~10 MB of Python. Only happens once — the browser caches it after.
What should the output look like?
You should see your question echoed back, then a random fortune from the list.
📖
How this works
A list keeps a bunch of things in order. random.choice() picks one at random. Together they make a magic 8-ball: put your fortunes in the list, and every run picks a different one.
Your turn — try these
- 1Add 5 of your own fortunes to the list.
- 2Change some fortunes based on the length of the question (long questions get long answers?).
- 3Add a chance the 8-ball refuses to answer certain forbidden questions.