Skip to main content

A fun and lighthearted Python package that emulates the classic Magic 8 Ball toy. This package allows users to ask questions and get random, playful responses. Built with rigorous software engineering practices, it serves as a joyful addition to any developer's toolbox.

Project description

Magic 8 Ball Python Package

Build Status

A fun and lighthearted Python package that emulates the classic Magic 8 Ball toy. This package allows users to ask questions and get random, playful responses. Built with rigorous software engineering practices, it serves as a joyful addition to any developer's toolbox.

Features

This package includes the following functions:

  • get_questions(language, count=0): Retrieve a list of sample questions.
  • ask_question(language, question=""): Ask a question and receive a random response.
  • shake_ball(language, shake_time=10): Shake the ball to get another response, with optional delay.
  • get_answers(language, count=0): Retrieve a list of sample answers.

Installation

To install the Magic 8 Ball package, use pip:

pip install magic_eight

Usage

To use the package, import the functions you need:

from magic_eight import get_questions, ask_question, shake_ball, get_answers

# Example usage
print(get_questions("en", 2))  # Get two sample questions
print(ask_question("en"))      # Ask a random question
print(shake_ball("en", 1))     # Shake the ball with a 1-second delay
print(get_answers("en", 3))    # Get three sample answers

Functions

get_questions(language, count=0)

Retrieve a list of sample questions in the specified language.

  • Parameters:

    • language (str): The language code (e.g., "en" for English).
    • count (int, optional): Number of questions to return. Default is 0, which returns all questions.
  • Returns: list of questions.

Example

get_questions("en", 2)
# Output: ["Will I pass this class", "Will tomorrow be a snow day"]

ask_question(language, question="")

Ask a question and get a random answer.

  • Parameters:

    • language (str): The language code.
    • question (str, optional): A specific question to ask. If empty, a random question is generated.
  • Returns: tuple of (question, answer).

Example

ask_question("en", "Will I pass this class")
# Output: ("Will I pass this class", "Maybe")

shake_ball(language, shake_time=10)

Shake the ball to get another response to the previous question.

  • Parameters:

    • language (str): The language code.
    • shake_time (int, optional): Time in seconds to simulate shaking. Default is 10.
  • Returns: str answer.

Example

shake_ball("en", 1)
# Output: "Yes"

get_answers(language, count=0)

Retrieve a list of sample answers in the specified language.

  • Parameters:

    • language (str): The language code.
    • count (int, optional): Number of answers to return. Default is 0, which returns all answers.
  • Returns: list of answers.

Example

get_answers("en", 3)
# Output: ["Don't count on it", "Yes", "No"]

Running Tests

To run the unit tests for this package, use the following command:

PYTHONPATH=src python -m unittest discover -s src/tests

Contribution Guidelines

If you’d like to contribute:

  1. Clone the repository and create a new feature branch.
  2. Make your changes in the feature branch.
  3. Create a pull request to merge into the main branch.
  4. Ensure all tests pass by running:
    PYTHONPATH=src python -m unittest discover -s src/tests
    
  5. Your code will be reviewed, and if everything is in order, it will be merged.

Developer Setup

  • Install dependencies: Use pipenv to set up a virtual environment:
    pipenv install
    
  • Run tests with pytest:
    pipenv run pytest
    
  • Build the package:
    pipenv run python -m build
    
  • Upload to PyPI:
    pipenv run twine upload dist/*
    

Example Program

Below is an example script demonstrating the use of all functions in this package:

from magic_eight import get_questions, ask_question, shake_ball, get_answers

# Get sample questions
print(get_questions("en", 2))

# Ask a question
print(ask_question("en", "Will I get the internship?"))

# Shake the ball for a new answer
print(shake_ball("en", 1))

# Get sample answers
print(get_answers("en", 3))

Contributors

Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

magic_eight_ball-0.1.0.tar.gz (44.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

magic_eight_ball-0.1.0-py3-none-any.whl (31.1 kB view details)

Uploaded Python 3

File details

Details for the file magic_eight_ball-0.1.0.tar.gz.

File metadata

  • Download URL: magic_eight_ball-0.1.0.tar.gz
  • Upload date:
  • Size: 44.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.6

File hashes

Hashes for magic_eight_ball-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6d25f1dfec9c0a63eabf0338e97d3006f681cafa37ff411c319c3b0c9059c5c1
MD5 44240046ef290c628329265ee9a8e2ef
BLAKE2b-256 c045cfae54a47d6410ae8c3c80b83c6619e92173b5289d3c25dcfb7bfdeda3cd

See more details on using hashes here.

File details

Details for the file magic_eight_ball-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for magic_eight_ball-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 88ef94b9816766f94ceaa1b54008e36b22cb0ad873573aebdb910ac6c4e09362
MD5 25565e81dcddeaaa4d99157ca581baa4
BLAKE2b-256 07c705cead08ec497363cc53dfa1de67855b4ae4c008e31042948fec69d2ce76

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page