-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtema_functii.py
58 lines (43 loc) · 1.28 KB
/
tema_functii.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
def sum_args(*args,**kwargs):
result = 0
for arg in args:
arg_type = type(arg)
if arg_type is not int and arg_type is not float:
continue
result += arg
return result
def sum_recursive(n):
sum_n = 0
sum_odd = 0
sum_even = 0
if n == 0:
#daca n este zero functia returneaza zero
return sum_n, sum_odd, sum_even
sum_n += n #adaugam n la suma
if n % 2:
#adaugam numere pare
sum_even += n
else:
#adaugam numere impare
sum_odd += n
#urmatorul n devine n-1 daca n este pozitiv
next_n = n-1
if n < 0:
#urmatorul n devine n+1 daca n este negativ
next_n = n+1
if next_n == 0:
#daca n este diferit de zero functia returneaza sumele curente
return sum_n, sum_odd, sum_even
#daca n nu este diferit de zero calculam sumele pentru next_n
_sum_n, _sum_odd, _sum_even = sum_recursive(next_n)
return sum_n + _sum_n, sum_odd + _sum_odd, sum_even + _sum_even
def print_input():
in_value = input('introduceti un numar: ')
try:
in_value = int(in_value)
except:
in_value = 0
print(f'numarul introduse este: {in_value}')
print(sum_args(1,1.1,'a',someval=2))
print(sum_recursive(-3))
print_input()