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

Uploaded Source

Built Distribution

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

Uploaded Python 3

Supported by

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