Skip to content

Commit

Permalink
1.3.4 - imports made easier and bug fixes
Browse files Browse the repository at this point in the history
Reshuffled files making imports a lot easier and minor bug fixes
  • Loading branch information
Sammygarch committed Jan 9, 2022
1 parent c4c2663 commit 505fe91
Show file tree
Hide file tree
Showing 11 changed files with 333 additions and 323 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ to learn and calculate equations that they often use.

## To import:
```
from school_algorithms import school_algorithms
import school_algorithms
```

Functions include:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setup(
name = "school_algorithms",
version = "1.2.3",
version = "1.3.4",
author = "Sammy Garcia",
author_email = "[email protected]",
description = "School algorithm module for Python",
Expand Down
5 changes: 5 additions & 0 deletions src/school_algorithms/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from .circle import *
from .physics import *
from .pythagorus import *
from .trapezium import *
from .triangle import *
4 changes: 4 additions & 0 deletions src/school_algorithms/_if_not_int_or_float_raise.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def _if_not_int_or_float_raise(*args):
for arg in args:
if type(arg) != int and type(arg) != float:
raise ValueError ("At least, one of the values wasn't an integer or a float.")
32 changes: 32 additions & 0 deletions src/school_algorithms/circle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from math import pi as _pi
from ._if_not_int_or_float_raise import _if_not_int_or_float_raise


def circle_area(r):
"""
Calculates the area of a trapezium using the formula:
area = \u03C0(radius squared)
Parameters
----------
r: int or float
The radius in the equation.
Returns
-------
Float
\u03C0 * (r**2)
Raises
------
ValueError
If r is not an integer or float
Examples
--------
>>> school_algorithms.circle_area(10)
314.1592653589793
"""
_if_not_int_or_float_raise(r)
return _pi * (r**2)
96 changes: 96 additions & 0 deletions src/school_algorithms/physics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
from ._if_not_int_or_float_raise import _if_not_int_or_float_raise

def power_calc(E, t):
"""Calculates power from energy and time using the formula:
power = energy / time
Parameters
----------
E : int or float
The energy value in the equation.
t : int or float
The time value of the equation.
Returns
-------
Float
E / t
Raises
------
ValueError
If E or t is not an integer or float
Examples
--------
>>> school_algorithms.power_calc(10, 5)
2.0
"""
_if_not_int_or_float_raise(E, t)
return E / t

def energy_calc(p, t):
"""
Calculates energy from power and time using the formula:
energy = power * time
Parameters
----------
p: Int or float
The power value of the equation.
t: Int or float
The time value of the equation.
Returns
-------
Int
p * t
Raises
------
ValueError
If p or t is not an integer or float
Examples
--------
>>> school_algorithms.energy_calc(5, 2)
10
"""
_if_not_int_or_float_raise(p, t)
return p * t

def time_calc(p, E):
"""
Calculates time from power and energy using the formula:
time = energy / power
Parameters
----------
p: int or float
The power value of the equation.
E: int or float
The energy value of the equaton.
Returns
-------
Float
E / p
Raises
------
ValueError
If p or E is not an integer or float
Examples
--------
>>> school_algorithms.energy_calc(10, 2)
5.0
"""
_if_not_int_or_float_raise(p, E)
return E / p
65 changes: 65 additions & 0 deletions src/school_algorithms/pythagorus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from math import sqrt as _sqrt
from ._if_not_int_or_float_raise import _if_not_int_or_float_raise

def pythag_leg(hy, a):
"""
Calculates the length of a leg in right-angled triangle using the formula:
leg(b) = the square-root of (hy squared - leg(a) squared)
Parameters
----------
hy: int or float
The hypotneus of the equation.
a: int or float
The leg of the equation.
Returns
-------
Float
sqrt(a**2 + b**2)
Raises
------
ValueError
If hy or a is not an integer or float.
Examples
--------
>>> school_algorithms.pythag_leg(7, 2)
6.708203932499369
"""
_if_not_int_or_float_raise(hy, a)
return _sqrt(hy**2 - a**2)

def pythag_hypot(a, b):
"""
Calculates the hypotenuse of a right angled triangle using the formula:
hypotenuse = the square-root of (leg(a) squared + leg(b) squared)
Parameters
----------
a: int or float
leg(a) of the equation.
b: int or float
leg(b) of the equation.
Returns
-------
Float
sqrt(a**2 + b**2)
Raises
------
ValueError
If a or b is not an integer or float
Examples
--------
>>> school_algorithms.pythag_hypot(4, 2)
4.47213595499958
"""
_if_not_int_or_float_raise(a, b)
return _sqrt(a**2 + b**2)
Loading

0 comments on commit 505fe91

Please sign in to comment.