Back

Code Challenge: Magic 8-Ball

Difficulty  

divider

Objective

Simulate a Magic 8-Ball. The user asks a question and gets one of six answers back at random.

The question never gets used in a calculation — asking for it just makes the toy feel real.

Skills to Practice

  • Prompting a user for input
  • Generating a random number with random
  • Branching with if / elif / else
  • Formatting custom output

Tasks

  • Create a new Python program named cc-magic-8-ball.
  • Prompt the user to ask the Magic 8-Ball a question.
  • Generate a random number, then use it to choose one of the six answers below.
  • Every one of the six must be reachable. Run it several times to check.
  • Display the chosen answer.
  • It is certain.
  • Without a doubt.
  • Ask again later.
  • Cannot predict now.
  • Don't count on it.
  • Outlook not so good.

Sample Output

Sample Output
Ask the Magic 8-Ball a question: Will I ace my exam? [Enter]
Magic 8-Ball says: Outlook not so good.

Commence Challenge