-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.py
57 lines (50 loc) · 1.62 KB
/
utils.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
##
## EPITECH PROJECT, 2018
## 108trigo_2017
## File description:
## Utils file
##
import sys
import math
from maths_functions import *
def tab_fcts():
fct_tab = [my_exp, my_cos, my_cosh, my_sinh]
def my_help():
print("USAGE\n"
"\t./108trigo fun a0 a1 a2....\n"
"\n"
"DESCRIPTION\n"
"\tfun\tfunction to be applied,"
' among at least "EXP", "COS", "SIN", "COSH" and "SINH"\n'
'\tai\tcoeficients of the matrix')
exit(0)
def check_parameters():
if "--help" in sys.argv or "-h" in sys.argv:
my_help()
if len(sys.argv) <= 2 or sys.argv[1] not in ["EXP", "COS", "SIN", "COSH", "SINH"]:
print("Missing arguments.\nUsage: ./108trigo fun a0 a1 a2 ...", file=sys.stderr)
exit(84)
try:
for i in range(2, len(sys.argv)):
sys.argv[i] = float(sys.argv[i])
except ValueError:
print("Argument %d (%s) isn't a number" % (i, sys.argv[i]), file=sys.sys.stderr)
exit(84)
def error_mngmt():
i = len(sys.argv) - 2
sqi = trunc(sqrt(i))
if trunc(sqrt(i)) ** 2 != i:
print("Missing arguments.\nUsage: ./108trigo fun a0 a1 a2 ...", file=sys.stderr)
exit(84)
return sqi
def print_matrix(tab):
for i in range(len(tab)):
for j in range(len(tab[i])):
print("%.2f%c" % (tab[i][j], '\t' if (j != len(tab[i]) - 1) else '\n'), end="")
def launch_func(tab):
args = ["EXP", "COS", "SIN", "COSH", "SINH"]
fct_tab = [my_exp, my_cos, my_sin, my_cosh, my_sinh]
for i in range(len(fct_tab)):
if sys.argv[1] == args[i]:
tab = fct_tab[i](tab)
return tab