-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1.3.4 - imports made easier and bug fixes
Reshuffled files making imports a lot easier and minor bug fixes
- Loading branch information
1 parent
c4c2663
commit 505fe91
Showing
11 changed files
with
333 additions
and
323 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.