1: # Program 1: simple loop printing numbers from 1 to 6.
2: i = 1
3: while i < 6:
4: print(i)
5: i += 1
6: print()
7:
8: print("Simple loop printing numbers from 1 to 6:")
9:
10:
11: (*
12: Program 2:
13: computes the factorial of 6.
14: *)
15:
16: i = 1
17: r = 1
18: while i <= 6: (* loop *)
19: r = i * r
20: i += 1
21: print("Computing factorial of 6 =", r)
22: print()
23:
24: # Program 3: computing the 10-th fibonacci number.
25: a = 0
26: b = 1
27: i = 0
28: while i < 10:
29: t = b
30: b = a + b
31: a = t
32: i += 1
33: print("Computing fibonacci of 10 =", a)
34: print()
35:
36:
37: # Program 4: checking whether a year is leap (i.e. there is February 29).
38:
39: year = 1900
40:
41: is_leap = (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0)
42: if is_leap:
43: print(year, "is_leap")
44: else:
45: print(year, "is not leap")