Python program to print below pattern -
1
2 4
1 3 5
2 4 6 8
-------------------------------------------------------
#!/usr/bin/python
for i in range(1,6):
if ((i % 2) or (i == 1)):
num = 1
else:
num =2
for j in range(0,i):
print num,
num += 2
else :
print '\n'
---------------------------------------------------------
Output -
1
2 4
1 3 5
2 4 6 8
-------------------------------------------------------
#!/usr/bin/python
for i in range(1,6):
if ((i % 2) or (i == 1)):
num = 1
else:
num =2
for j in range(0,i):
print num,
num += 2
else :
print '\n'
---------------------------------------------------------
Output -
Comments