forked from lcompilers/lpython
-
Notifications
You must be signed in to change notification settings - Fork 0
/
loop1.py
43 lines (35 loc) · 725 Bytes
/
loop1.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
from lpython import i32, i64
def test_factorial_1(x: i32) -> i32:
if x < 0:
return 0
result: i32
result = 1
while x > 0:
result = result * x
x -= 1
return result
def test_factorial_2(x: i32) -> i32:
result: i32
result = 1
i: i32
for i in range(1, x + 1):
result = result * i
return result
def test_factorial_3(x: i32) -> i64:
result: i64
result = i64(0)
if x < 0:
return result
result = i64(1)
while x > 0:
result = result * i64(x)
x -= 1
return result
def main0():
i: i32
i = test_factorial_1(4)
i = test_factorial_2(4)
j: i64
j = test_factorial_3(5)
#print(i, j)
main0()