-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
49 lines (37 loc) · 1.18 KB
/
Copy pathutils.py
File metadata and controls
49 lines (37 loc) · 1.18 KB
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
from math import *
# Math library
# Author: Sébastien Combéfis
# Version: February 2, 2016
def fact(n):
"""Computes the factorial of a natural number.
Pre: -
Post: Returns the factorial of 'n'.
Throws: ValueError if n < 0
"""
if n < 0 :
raise ValueError
elif n<2:
return 1
else:
return n*fact(n-1)
def roots(a, b, c):
"""Computes the roots of the ax^2 + bx + x = 0 polynomial.
Pre: -
Post: Returns a tuple with zero, one or two elements corresponding
to the roots of the ax^2 + bx + c polynomial.
"""
delta = (b*b)-(4*a*c)
if delta < 0 :
return None
elif delta == 0 :
return -b/2*a
elif delta > 0 :
return (-b+sqrt(delta))/2*a, (-b-sqrt(delta))/2*a
'''def integrate(function, lower, upper):
"""Approximates the integral of a fonction between two bounds
Pre: 'function' is a valid Python expression with x as a variable,
'lower' <= 'upper',
'function' continuous and integrable between 'lower‘ and 'upper'.
Post: Returns an approximation of the integral from 'lower' to 'upper'
of the specified 'function'.
"""'''