Skip to content

A simple python package to replicate a Magic 8Ball.

License

Notifications You must be signed in to change notification settings

TheGrotShop/magic8ball

Repository files navigation

TheGrotShop logo
Github Build Status License Created
Release Released Commits since release

Overview

Overview

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.

Features

  • 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.

Installation

pip install wolfsoftware.magic8ball

Usage

Basic Example

Once installed, you can use the Magic 8-Ball package in your Python code.

from wolfsoftware.magic8ball import Magic8Ball

# Create an instance of Magic8Ball
magic_ball = Magic8Ball()

# Ask a yes/no question
response = magic_ball.ask_question("Will it rain tomorrow?")
print("Magic 8-Ball says:", response)

Handling Errors

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, InvalidQuestionError

magic_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)