quilt_lang package¶
Module contents¶
The Math Ext file
-
mathext.
amountdiv
(num, minnum, maxnum)¶ Get the amount of numbers divisable by a number.
Parameters: - number – The number to use.
- minnum (integer) – The minimum number to check.
- maxnum (integer) – The maximum number to check.
>>> amountdiv(20, 1, 15) 5
-
mathext.
circleconvert
(amount, currentformat, newformat)¶ Convert a circle measurement.
Parameters: - amount (number) – The number to convert.
- currentformat (string) – The format of the provided value.
- newformat (string) – The intended format of the value.
>>> circleconvert(45, "radius", "radius") 45
>>> circleconvert(45, "radius", "diameter") 90
>>> circleconvert(45, "radius", "circumference") 282.7433388230814
>>> circleconvert(45, "diameter", "diameter") 45
>>> circleconvert(45, "diameter", "radius") 22.5
>>> circleconvert(45, "diameter", "circumference") 141.3716694115407
>>> circleconvert(45, "circumference", "circumference") 45
>>> circleconvert(45, "circumference", "radius") 7.16197243913529
>>> circleconvert(45, "circumference", "diameter") 14.32394487827058
>>> circleconvert(45, "foo1", "foo2") Traceback (most recent call last): ... ValueError: Invalid old format provided.
>>> circleconvert(45, "radius", "foo") Traceback (most recent call last): ... ValueError: Invalid new format provided.
>>> circleconvert(45, "diameter", "foo") Traceback (most recent call last): ... ValueError: Invalid new format provided.
>>> circleconvert(45, "circumference", "foo") Traceback (most recent call last): ... ValueError: Invalid new format provided.
-
mathext.
convertbase
(num, base=10)¶ Convert a number in base 10 to another base
Parameters: - num (number) – The number to convert.
- base (integer) – The base to convert to.
>>> convertbase(20, 6) '32'
-
mathext.
cube
(num)¶ Check if a number is cube
Parameters: num (number) – The number to check. >>> cube(8) True
-
mathext.
even
(num)¶ Check if a number is even
Parameters: num (number) – The number to check. >>> even(2) True
-
mathext.
factorial
(num)¶ Find the factorial of a number
Parameters: num (integer) – The number to find the factorial for. >>> factorial(4) 24
-
mathext.
fib
(num)¶ Check if a number is in the Fibonacci sequence.
Parameters: num (integer) – The number to check. >>> fib(8) True
>>> fib(4) False
-
mathext.
flipcoords
(xcoord, ycoord, axis)¶ Flip the coordinates over a specific axis, to a different quadrant
Parameters: - xcoord (integer) – The x coordinate to flip
- ycoord (integer) – The y coordinate to flip
- axis (string) – The axis to flip across. Could be ‘x’ or ‘y’
>>> flipcoords(-5, 5, "y") (5, 5)
>>> flipcoords(5, 5, "y") (-5, 5)
>>> flipcoords(0, -5, "y") (0, -5)
>>> flipcoords(-5, -5, "x") (-5, 5)
>>> flipcoords(5, 5, "x") (5, -5)
>>> flipcoords(0, -5, "x") (0, 5)
>>> flipcoords(-5, 0, "x") (-5, 0)
>>> flipcoords(5, 5, "foo") Traceback (most recent call last): ... ValueError: Invalid axis. Neither x nor y was specified.
-
mathext.
fracsimplify
(numerator, denominator)¶ Simplify a fraction.
Parameters: - numerator (integer) – The numerator of the fraction to simplify
- denominator (integer) – The denominator of the fraction to simplify
Returns: The simplified fraction
Return type: list
>>> fracsimplify(2, 4) (1, 2)
-
mathext.
getprime
(n)¶ Get the nth prime number
Parameters: n (integer) – The number representing n. >>> getprime(3) 5
-
mathext.
hcf
(num1, num2)¶ Find the highest common factor of 2 numbers.
Parameters: - num1 (number) – The first number to find the hcf for
- num2 (number) – The second number to find the hcf for
>>> hcf(5, 10) 5
-
mathext.
lcm
(num1, num2)¶ Find the lowest common multiple of 2 numbers
Parameters: - num1 (number) – The first number to find the lcm for
- num2 (number) – The second number to find the lcm for
>>> lcm(4, 8) 8
>>> lcm(0, 0) 0
-
mathext.
negative
(num)¶ Check if a number is negative (less than 0)
Parameters: num (number) – The number to check. >>> negative(-1) True
-
mathext.
nothing
(variable)¶ Check if a variable is essentially nothing.
Parameters: variable (variable) – The variable to check. >>> nothing(0) True
-
mathext.
num
(value)¶ Check if a value is a type of number (decimal or integer).
Parameters: value (object) – The value to check. >>> num(1) True
-
mathext.
odd
(num)¶ Check if a number is odd
Parameters: num (number) – The number to check. >>> odd(3) True
-
mathext.
positive
(num)¶ Check if a number is positive (more than 0)
Parameters: num (number) – The number to check. >>> positive(1) True
-
mathext.
posneg
(num)¶ Toggle a number between positive and negative.
The converter works as follows: - 1 > -1 - -1 > 1 - 0 > 0
Parameters: num (number) – The number to toggle. >>> posneg(2) -2
-
mathext.
prime
(num)¶ Check if a number is a prime number.
Parameters: num (integer) – The number to check. >>> prime(7) True
>>> prime(1) False
-
mathext.
pyth
(first, second)¶ Calculate the area of a right angled trangle based on Pythagoras’ Theorem.
Parameters: - first (number) – The length of the first axis (x or y)
- second (number) – The length of the second axis (x or y)
>>> pyth(3, 5) 7.5
-
mathext.
quadrant
(xcoord, ycoord)¶ Find the quadrant a pair of coordinates are located in
Parameters: - xcoord (integer) – The x coordinate to find the quadrant for
- ycoord (integer) – The y coordinate to find the quadrant for
>>> quadrant(5, 5) 1
>>> quadrant(-5, 5) 2
>>> quadrant(-5, -5) 3
>>> quadrant(5, -5) 4
-
mathext.
shapesides
(inputtocheck, inputtype='shape')¶ Get the sides of a shape.
Parameters: - inputtocheck (string or number) – The amount of sides or the shape to be checked, depending on the value of inputtype.
- inputtype (string) – The type of input provided. Can be: ‘shape’, ‘sides’.
>>> shapesides(3, "sides") 'triangle'
>>> shapesides("n", "sides") 'ngon'
>>> shapesides("N", "sides") 'ngon'
>>> shapesides("foo", "sides") 'ngon'
>>> shapesides("ngon", "shape") 'n'
>>> shapesides("triangle", "shape") 3
>>> shapesides("foo", "shape") 'n'
>>> shapesides("foo", "foo") Traceback (most recent call last): ... ValueError: Invalid input type.
-
mathext.
sigmoid
(num)¶ Find the sigmoid of a number.
Parameters: number (number) – The number to find the sigmoid of Returns: The result of the sigmoid Return type: number >>> sigmoid(1) 0.7310585786300049
-
mathext.
square
(num)¶ Check if a number is square
Parameters: num (number) – The number to check. >>> square(4) True
-
mathext.
triangular
(num)¶ Check if a number is triangular
Parameters: num (number) – The number to check. >>> triangular(5) True
-
mathext.
zero
(num)¶ Check if a number is zero
Parameters: num (number) – The number to check. >>> zero(0) True
Constants¶
mathext.
phi
- The value of phi.