Skip to main content

A simple averager

Project description

Getting started

Averager

This is the most basic class in the averager module. It allows you to simply average any quantity of numbers.

import averager
instance = averager.Averager
print(instance.average(1, 5))
# 3

Usage

The Averager class allows you to make an instance, and then use its average method with any quantity of numbers as the parameters. The average method will return a float object, or an int object if it is equivalent. For example, instead of 3.0, it returns 3, but 5.5 stays the same.

import averager
print(averager.Averager.average(1, 5))
# 3

WeightedAverager

The WeightedAverager class is very similar to the Averager class, but the WeightedAverager class allows you to set different weights to be used when averaging numbers.

import averager
instance = averager.WeightedAverager(a=1, b=2, c=3)
print(instance.average(a=1, c=2))
# 1.75

Usage

Usage of the WeightedAverager class is similar to that of the Averager class. First, initialize an instance of the class, passing keyword arguments with the labels for your numbers and the weights attached to those labels. These labels will need to be used again. Then, run the instance's average method, passing keyword arguments with some or all of the labels you specified in the initialization, as well as values for each one. The method will take into account the weight for each number specified, and will average the numbers accordingly.

Potential errors

  • When initializing an instance of the WeightedAverager, if a weight below zero is passed, a ValueError will be raised.
  • When running the average method, if a label is passed that does not have a weight assigned to it, a KeyError will be raised.

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

averager-1.0.3.tar.gz (2.0 kB view details)

Uploaded Source

Built Distribution

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

averager-1.0.3-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

Details for the file averager-1.0.3.tar.gz.

File metadata

  • Download URL: averager-1.0.3.tar.gz
  • Upload date:
  • Size: 2.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0

File hashes

Hashes for averager-1.0.3.tar.gz
Algorithm Hash digest
SHA256 434860282f162fbf84b1385d95b69fdd2e9037cfcb73f764fa5656afa91a80f5
MD5 4364d5b88ca3c59cd4557aeecc58b5f3
BLAKE2b-256 0c0443c0634314b9491efcb75f13370c3d93eaf57f7232f626d1df484be9bb7a

See more details on using hashes here.

File details

Details for the file averager-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: averager-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 14.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0

File hashes

Hashes for averager-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 100be98287f271a0d486399d8fc55ca9e0dc0e849f2a10e263e069b8adbe0545
MD5 d7e1c234d3a351de092e664b6b03c0a0
BLAKE2b-256 7dadeb2d322f51e5876c73bfeedfcec7cd39deb429d63178cf5ff65f85b5588c

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