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_ball

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 in the given language
print(ask_question("fr"))      # Ask a random question and get an answer in the given language
print(shake_ball("en", 2))     # Shake the ball with a 2-second delay
print(get_answers("es", 3))    # Get three sample answers in the given language

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 have a good day today?", "Should I go for that job interview?"]

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("fr", "Vais-je atteindre mes objectifs cette année?")
# Output: ("Vais-je atteindre mes objectifs cette année?", "Oui, absolument!")

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("es", 1)
# Output: "Sí."

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: ["Yes, definitely!",  "It is certain.", "Without a doubt."]

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("fr", 2))

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

# Shake the ball for a new answer
print(shake_ball("es", 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.2.0.tar.gz (45.1 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.2.0-py3-none-any.whl (31.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: magic_eight_ball-0.2.0.tar.gz
  • Upload date:
  • Size: 45.1 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.2.0.tar.gz
Algorithm Hash digest
SHA256 753159dcec0cae81cbf3c50610b4c4e3d123599764484d9bc035e6bcf4832fcf
MD5 f3ef26a5e057fda6a371b66b1d6f8f15
BLAKE2b-256 80bbf1fb89c6b77949d5aae4f1f96becfde55f3dffb91738a664e134fab43636

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for magic_eight_ball-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7bd12e8bd0b14218730e2f692437fccf1f167371875bb65b3289d831bae679ea
MD5 ac10675418c2ec7fdc1e3d9bca64aeaf
BLAKE2b-256 10048c835599a9da5466dfa40e7c556c0186c8abd2682ec44fd5d2ef83c2b6bc

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