-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathNumber-Triangles.py
89 lines (84 loc) · 1.06 KB
/
Number-Triangles.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
'''
1
12
123
1234
12345
'''
for i in range(1,6):
for j in range(1,i+1):
print(j,end='')
print()
'''
1
22
333
4444
55555
'''
# Nested for loop
for i in range(1,6):
for j in range(1,i+1):
print(i,end='')
print()
# Single for loop
for i in range(1,6):
print(str(i)*i,end='')
print()
'''
1
10
101
1010
10101
'''
for i in range(1,6):
for j in range(1,i+1):
if j%2==0:
print("0",end='')
else:
print("1",end='')
print('')
'''
1
101
10101
1010101
'''
for i in range(1,8,2):
for j in range(1,i+1):
if j%2==0:
print("0",end='')
else:
print("1",end='')
print('')
'''
55555
4444
333
22
1
'''
for i in range(5,0,-1):
for j in range(1,i+1):
print(i,end='')
print()
'''
56789
6789
789
89
9
'''
## Method 1
n='56789'
for i in range(len(n)):
print(' '*i,end=' ')
print(n[i:])
## Method 2
for i in range(1,6):
for sp in range(6,i,-1):
print(' ',end='')
for j in range(0,i):
print('* ',end='')
print('')