-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmathfunctions.py
More file actions
43 lines (29 loc) · 806 Bytes
/
mathfunctions.py
File metadata and controls
43 lines (29 loc) · 806 Bytes
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
def equation(equation):
if '^' in equation:
equation = str.replace(equation, '^', '**')
return eval(equation)
def mean(numbers):
mean = 0
for i in numbers:
mean += float(i)
return mean / (len(numbers) - 1)
def rt(squared, power, places):
guess = squared
while True:
change = ((guess**power) - squared)/(power*guess**(power - 1))
guess -= change
if (change < 10**(-places)):
break
return round(guess, places)
def prime(tested_number):
number = 2
prime = True
while Prime == True and number < tested_number / 2:
if tested_number % number == 0:
prime = False
else:
number += 1
if prime == False:
return 0
else:
return 1