A simple package to implement a Magic 8Ball.
Project description
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)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file wolfsoftware_magic8ball-0.1.0.tar.gz
.
File metadata
- Download URL: wolfsoftware_magic8ball-0.1.0.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.13.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb899c2815c857d1915d5d88374ebfd884b5a0e135362f75114ace9a5384bd37 |
|
MD5 | 9dc69f40dfc492317f31b69eb2228f09 |
|
BLAKE2b-256 | e5adf0696a385d067a925e525e34ae72b9b97540a7d88972b1673a8db703f598 |
File details
Details for the file wolfsoftware.magic8ball-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: wolfsoftware.magic8ball-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.13.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc94beac4fffd8a66eab0777731cc4933a06ed6b3530715a361614afa7b2a8b5 |
|
MD5 | 438390e11a09b4438f18ed9b2746fca0 |
|
BLAKE2b-256 | 370a7b890ed078c6f516bbb3892e2bce7e3efee658a03cd945007ccc4dd3f39d |