magic8ball
v0.1.0
Magic 8-Ball
is a Python package that emulates the classic Magic 8-Ball toy, providing randomized responses to yes-or-no questions. This package is
designed to be both interactive and usable in various applications, allowing developers to integrate a fun, nostalgic feature into their projects.
20 traditional Magic 8-Ball responses (positive, neutral, and negative).
Simple API to ask questions and get a response.
Custom error handling for invalid inputs.
Includes comprehensive test coverage.
pip install wolfsoftware.magic8ball
Once installed, you can use the Magic 8-Ball package in your Python code.
from wolfsoftware.magic8ball import Magic8Ball# Create an instance of Magic8Ballmagic_ball = Magic8Ball()# Ask a yes/no questionresponse = magic_ball.ask_question("Will it rain tomorrow?")print("Magic 8-Ball says:", response)
The ask_question
method raises an InvalidQuestionError
if the question provided is not a non-empty string. Make sure to validate the input or handle
this exception as shown:
from wolfsoftware.magic8ball import Magic8Ball, InvalidQuestionErrormagic_ball = Magic8Ball()try:response = magic_ball.ask_question("Will I get a promotion?")print("Magic 8-Ball says:", response)except InvalidQuestionError as e:print("Error:", e)