Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

A simple averager

Project description

Getting started

Codacy Badge Build Status GitHub release PyPI GitHub issues GitHub pull requests License


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


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


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 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.

Files for averager, version 1.0.5
Filename, size File type Python version Upload date Hashes
Filename, size averager-1.0.5-py3-none-any.whl (15.0 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size averager-1.0.5.tar.gz (2.4 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page