Created
November 22, 2021 03:49
-
-
Save Otumian-empire/7e8ba119fae774ff5e777491683b7b56 to your computer and use it in GitHub Desktop.
We are going to import a lot of things from the math module thus to keep it structured we shall group them as tuples though it will work fine anyway.
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
# import objects from the math lib | |
# making use of some constants such as `pi` and `e`, | |
# some trig function like the cosine and sine | |
# and other functions | |
from math import ( | |
pi, e, | |
cos, sin, tan, | |
sqrt, pow, exp, | |
gcd, factorial | |
) | |
# pi and e | |
# area of a circle = pi times radius square | |
radius = 7 # cm | |
# area = pi * radius ** 2 | |
# area = pi * radius * radius | |
area = pi * pow(radius, 2) | |
print(f"The area of the circle of radius, {radius} is {round(area,2)}cm^2") | |
print(end='\n\n') | |
# e(n) for some integer `n` , is the same as e ** n, pow(e, n) and e * e * ...n | |
# lets check if they are actually | |
if e * e == pow(e, 2) == e ** 2: | |
result = "Cool, e ** n, pow(e, n) and e * e * ...n" | |
result += " all the same" | |
else: | |
result = "Sorry, they are not the same" | |
print(result, end='\n\n') | |
# cos, sin and tan | |
# given that theta is 60 degree | |
theta = 60 # degree | |
print(f"Trig table for degree, {theta}") | |
print("-------------------------") | |
print(f"cos({theta}) {cos(theta)}") | |
print(f"sin({theta}) {sin(theta)}") | |
print(f"tan({theta}) {tan(theta)}") | |
print(end='\n\n') | |
# gcd and factorial | |
# we shall roughly make use of type hinting | |
# gcd of 81 and 72 | |
first_int: int = 81 | |
second_int: int = 72 | |
gcd_int: int = gcd(first_int, second_int) | |
print(f"the gcd of {first_int} and {second_int} is {gcd_int}") | |
# the factorial of gcd_int | |
fact_int: int = factorial(gcd_int) | |
print(f"The factorial, {gcd_int}!, is {fact_int}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment