vault backup: 2023-11-20 14:11:33
This commit is contained in:
parent
d0de81cc65
commit
227bbc4c71
@ -14,7 +14,7 @@ def zorglub(n: int) -> int:
|
|||||||
The function return the sum of the factorial of n
|
The function return the sum of the factorial of n
|
||||||
|
|
||||||
## Exercise 1.2
|
## Exercise 1.2
|
||||||
```
|
```python
|
||||||
def multiplication(x: int, y: int) -> int:
|
def multiplication(x: int, y: int) -> int:
|
||||||
result = 0
|
result = 0
|
||||||
while y > 0:
|
while y > 0:
|
||||||
@ -22,41 +22,8 @@ def multiplication(x: int, y: int) -> int:
|
|||||||
y -= 1
|
y -= 1
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def multiplication2(x: int, y: int) -> int:
|
|
||||||
result = 0
|
|
||||||
if x < 0 and y < 0:
|
|
||||||
i = 0
|
|
||||||
x = -x
|
|
||||||
y = -y
|
|
||||||
while i < y:
|
|
||||||
result = result + x
|
|
||||||
i += 1
|
|
||||||
return result
|
|
||||||
elif y < 0:
|
|
||||||
y = -y
|
|
||||||
i = 0
|
|
||||||
while i < y:
|
|
||||||
result = result + x
|
|
||||||
i += 1
|
|
||||||
return -result
|
|
||||||
else:
|
|
||||||
i = 0
|
|
||||||
while i < y:
|
|
||||||
result = result + x
|
|
||||||
i += 1
|
|
||||||
return result
|
|
||||||
|
|
||||||
def multiplication2(x: int, y: int) -> int:
|
def multiplication2(x: int, y: int) -> int: # Thanks Hugo :p
|
||||||
if x < 0 and y < 0:
|
|
||||||
return multiplication(-x, -y)
|
|
||||||
elif y < 0:
|
|
||||||
return -multiplication(x, -y)
|
|
||||||
elif x < 0:
|
|
||||||
return -multiplication(-x, y)
|
|
||||||
else
|
|
||||||
return multiplication(x, y)
|
|
||||||
|
|
||||||
def multiplication2(x: int, y: int) -> int:
|
|
||||||
if y < 0:
|
if y < 0:
|
||||||
y = -y
|
y = -y
|
||||||
if x < 0:
|
if x < 0:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user