40 lines
587 B
Markdown
40 lines
587 B
Markdown
## Exercise 1.1
|
|
```python
|
|
def zorglub(n: int) -> int:
|
|
j = 1
|
|
k = 0
|
|
i = 1
|
|
while i <= n:
|
|
j = i * j
|
|
k = j + k
|
|
i = i + 1
|
|
return k
|
|
```
|
|
|
|
The function return the sum of the factorial of n
|
|
|
|
## Exercise 1.2
|
|
```python
|
|
def multiplication(x: int, y: int) -> int:
|
|
result = 0
|
|
while y > 0:
|
|
m += x
|
|
y -= 1
|
|
return result
|
|
|
|
|
|
def multiplication2(x: int, y: int) -> int: # Thanks Hugo :p
|
|
if y < 0:
|
|
y = -y
|
|
if x < 0:
|
|
return multiplication(-x, y)
|
|
return -multiplication(x, y)
|
|
else
|
|
return multiplication(x, y)
|
|
|
|
```
|
|
|
|
## Exercise 1.3
|
|
```
|
|
def exponentiation(x: int, n: int) -> int:
|
|
|