-
Notifications
You must be signed in to change notification settings - Fork 0
/
fx_ej2.py
53 lines (39 loc) · 1.2 KB
/
fx_ej2.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
from random import randint
def potencia(*args):
if len(args) == 1:
return(int(args[0])*int(args[0]))
elif len(args) == 2:
res = 1
for i in range(args[1]):
res *= args[0]
return res
def fibo(n):
if n <= 1:
return 1
return fibo(n-1) + fibo(n-2)
def main():
print("Fibonacci, primeros 20")
for i in range(20):
print("{} ".format(fibo(i)), end="")
print()
print("Cuadrados, primeros 20")
for i in range(20):
print("{} -> {} ".format(i, potencia(i)), end="")
print()
print("Cubos, primeros 20")
for i in range(20):
print("{} -> {} ".format(i, potencia(i, 3)), end="")
print()
print("Stress test 1")
for i in range(20):
base = randint(1, 10)
exponente = randint(1, 10)
print("{}^{} = {} ".format(base, exponente, potencia(base, exponente)), end="")
print()
print("Stress test 2")
for i in range(20):
base = randint(1, 100)
exponente = randint(1, 100)
print("{}^{} = {} ".format(base, exponente, potencia(base, exponente)), end="")
if __name__ == "__main__":
main()