-
Notifications
You must be signed in to change notification settings - Fork 1
/
math.py
116 lines (88 loc) · 3.15 KB
/
math.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import math
avg_list = []
print ("Hello this is the Math Formula Calculator. \nPlease type in the number that corresponds to the desired formula")
print(" 1. Quadratic Formula \n 2. Average \n 3. Distance Formula \n 4. Interest")
def choice_checker (x):
if x != "1" and x != "2" and x != "3" and x != "4":
print("That was not one of the choices. Try again")
user_input()
elif x == "1":
print("Welcome to the quadratic formula \nPlease put in the numbers for a,b, and c")
quad_input()
elif x == "2":
print('Welcome to the average calculator \nEnter in the numbers and type "done" when all numbers are typed in')
avg_input()
elif x == "3":
print("Welcome to the distance formula \nEnter in the coordiantes of the points appropiately")
dist_input()
elif x == "4":
print('Welcome to the interest calculator \nType "simple" for simple interest and "compound" for compound interest')
interest_selector()
def user_input ():
form_num = input("Number:")
choice_checker(form_num)
def interest_selector():
interest_type = input(">")
interest_checker(interest_type)
def interest_checker(x):
if x == "simple":
simple_input()
elif x == "compound":
compound_input()
else:
print("Not one of the choices. Try again")
interest_selector()
def quad_formula (a,b,c):
resultList = []
x = (-b + math.sqrt((b**2) - (4*a*c))) / (2*a)
resultList.append(x)
z = (-b - math.sqrt((b**2) - (4*a*c))) / (2*a)
resultList.append(z)
return resultList
def quad_input():
num_a = int(input("a:"))
num_b = int(input("b:"))
num_c = int(input("c:"))
quad_answer = quad_formula(num_a, num_b, num_c)
print("The answers are", quad_answer[0], "and", quad_answer[1])
def avg_input():
avg_num = input(">")
avg_checker(avg_num)
def avg_checker(x):
if x != "done":
avg_list.append(x)
avg_input()
else:
avg_answer = (avg_formula()) / (len(avg_list))
print("The average is", avg_answer)
def avg_formula():
avg_total = 0
for x in range(0, len(avg_list)):
avg_total += int(avg_list[x])
return avg_total
def dist_input():
x_coord1 = int(input("X-coordinate of first point:"))
y_coord1 = int(input("Y-coordinate of first point:"))
x_coord2 = int(input("X-coordinate of second point:"))
y_coord2 = int(input("Y-coordinate of second point:"))
distance_ans = dist_formula(x_coord1, y_coord1, x_coord2, y_coord2)
print("The distance between the two points is", distance_ans)
def dist_formula(w,x,y,z):
distance = math.sqrt(((y - w)**2) + ((z - x)**2))
return distance
def simple_input():
princ = int(input("Principle amount that you have:"))
interest = int(input("Interest rate per period:"))
time = int(input("The time for which the money is borrowed or lent:"))
simple_ans = princ * (interest / 100) * time
print("The total simple interest is", "$" + str(simple_ans))
def compound_input():
princ = int(input("Principle amount that you have:"))
interest = int(input("Compound interest rate per period:"))
time = int(input("Number of periods:"))
compound_ans = compound_interest(princ, interest, time)
print("The compound interest is", "$" + str(compound_ans))
def compound_interest(x,y,z):
comp_ans = x * (1 + (y / 100)) ** z - x
return comp_ans
user_input()