Ascending incremental Patterns:
-------------------------------
# Write a program to print the following pattern. assume the number of rows is 5.
1. Use the While Loop
2. Use the Nested While Loop
3. Use For Loop
4. Use Nested For loop
*
* *
* * *
* * * *
* * * * *
Solution:
number= int(input('Enter no of rows:'))#5
print('Using While Loop')
print('________________________')
a=0
while a<=number:
print('*'*a)
a=a+1
print('Using Nested While Loop')
print('________________________')
a=0
while a<=number:
b=0
while b<=a:
print('*', end='')
b = b +1
print()
a=a+1
print('Using For Loop')
print('________________________')
for a in range(number+1):
print(a*'*')
print('Using Nested For Loop')
print('________________________')
for a in range(number+1):
for b in range (a):
print('*', end='')
print()
#______________________________________________________________________________________________________________________
# Write a program to print the following pattern. assume the number of rows is 5.
1. Use the While Loop
2. Use the Nested While Loop
3. Use For Loop
4. Use Nested For loop
Ex:
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
# For Loop
print('Using For Loop')
print('________________________')
# n = int(input('Enter no of rows:'))#5
n = 5
for i in range(n): # 0,1,2,3,4
print((str(i + 1) + ' ') * (i + 1))
# Nested For Loop
print('Using Nested For Loop')
print('________________________')
for a in range(1, 5):
# print("outer loop -", a,end=' ')
for b in range(1, a + 1):
# print('inner loop-',a)
print(a, end=' ')
else:
print()
# Nested While Loop:
print('Using Nested While Loop')
print('________________________')
# n = int(input('Enter no of rows:')) # 5
n = 5
a = 1
while a <= n:
# print("outer loop -", a,end=' ')
b = 1
while b <= a:
# print('inner loop-',a)
print(a, end=' ')
b = b + 1
else:
print()
a = a + 1
else:
pass
#_______________________________________________________________________________________________________________________
# Write a program to print the following pattern. assume the number of rows is 5.
1. Use the While Loop
2. Use the Nested While Loop
3. Use For Loop
4. Use Nested For loop
Ex:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
# For Loop
print('Using For Loop')
print('________________________')
print('Using While Loop')
print('________________________')
# Nested For Loop
# n = int(input('Enter no of rows:')) # 5
n = 5
for a in range(1, n + 1):
# print("outer loop -", a,end=' ')
# print(a,end=' ')
for b in range(1, a + 1):
# print('inner loop-',a)
print(b, end=' ')
else:
print()
# Nested While Loop:
print('Using Nested While Loop')
print('________________________')
# n = int(input('Enter no of rows:')) # 5
n = 5
a = 1
while a <= n :
# print("outer loop -", a,end=' ')
b = 1
while b <= a :
# print('inner loop-',a)
print(b, end=' ')
b = b + 1
else:
print()
a = a + 1
else:
pass
#_______________________________________________________________________________________________________________________
# Write a program to print the following pattern. assume the number of rows is 5.
1. Use the While Loop
2. Use the Nested While Loop
3. Use For Loop
4. Use Nested For loop
Ex:
A
B B
C C C
D D D D
E E E E E
# For Loop
print('Using For Loop')
print('________________________')
n = int(input('Enter no of rows:'))#5
for i in range(n):#0,1,2,3,4
print((chr(65+i)+' ')*(i+1))
print('Using While Loop')
print('________________________')
# Nested For Loop
print('Using Nested For Loop')
print('________________________')
# n = int(input('Enter no of rows:')) # 5
n = 5
for a in range(1, n+1):
# print("outer loop -", a,end=' ')
for b in range(1, a + 1):
# print('inner loop-',a)
print(chr(64+a), end=' ')
else:
print()
# Nested While Loop:
print('Using Nested While Loop')
print('________________________')
# n = int(input('Enter no of rows:')) # 5
n = 5
a = 1
while a <= n:
# print("outer loop -", a,end=' ')
b = 1
while b <= a:
# print('inner loop-',a)
print(chr(64+a), end=' ')
b = b + 1
else:
print()
a = a + 1
else:
pass
#_______________________________________________________________________________________________________________________
# Write a program to print the following pattern. assume the number of rows is 5.
1. Use the While Loop
2. Use the Nested While Loop
3. Use For Loop
4. Use Nested For loop
Ex
A
A B
A B C
A B C D
A B C D E
# For Loop
print('Using For Loop')
print('________________________')
print('Using While Loop')
print('________________________')
# Nested For Loop
# n = int(input('Enter no of rows:')) # 5
n = 5
for a in range(1, n + 1):
# print("outer loop -", a,end=' ')
# print(a,end=' ')
for b in range(1, a + 1):
# print('inner loop-',a)
print(chr(64+b), end=' ')
else:
print()
# Nested While Loop:
print('Using Nested While Loop')
print('________________________')
# n = int(input('Enter no of rows:')) # 5
n = 5
a = 1
while a <= n :
# print("outer loop -", a,end=' ')
b = 1
while b <= a :
# print('inner loop-',a)
print(chr(64+b), end=' ')
b = b + 1
else:
print()
a = a + 1
else:
pass
#_______________________________________________________________________________________________________________________
# Write a program to print the following pattern. assume the number of rows is 5.
1. Use the While Loop
2. Use the Nested While Loop
3. Use For Loop
4. Use Nested For loop
Ex:
5
5 4
5 4 3
5 4 3 2
5 4 3 2 1
a=1
n=5
while a<=n:
b=0
while b<a:
print(n-b,end=' ')
b=b+1
print( )
a=a+1
a=1
n=5
while a<=n:
b=1
c=n
while b<=a:
print(c,end=' ')
c=c-1
b=b+1
print( )
a=a+1
print("____________")
#_______________________________________________________________________________________________________________________
# Write a program to print the following pattern. assume the number of rows is 5.
1. Use the While Loop
2. Use the Nested While Loop
3. Use For Loop
4. Use Nested For loop
Ex:
E
E D
E D C
E D C B
E D C B A
a=1
n=5
while a<=n:
b=0
while b<a:
print(chr(65+n-b),end=' ')
b=b+1
print( )
a=a+1
#_______________________________________________________________________________________________________________________
#Descendign Patterns:
# Write a program to print the following pattern. assume the number of rows is 5.
1. Use the While Loop
2. Use the Nested While Loop
3. Use For Loop
4. Use Nested For loop
n = 5
* * * * *
* * * *
* * *
* *
*
n = int(input('Enter no of rows:'))#5
for i in range(n):#0,1,2,3,4
print('* '*(n-i))
#__________________________________________________________________________________
# Write a program to print the following pattern. assume the number of rows is 5.
1. Use the While Loop
2. Use the Nested While Loop
3. Use For Loop
4. Use Nested For loop
Ex:
1 1 1
2 2
3
n = int(input('Enter no of rows:'))#5
for i in range(n):#0,1,2,3,4
print((str(i+1)+' ')*(n-i))
#__________________________________________________________________________________
# Write a program to print the following pattern. assume the number of rows is 5.
1. Use the While Loop
2. Use the Nested While Loop
3. Use For Loop
4. Use Nested For loop
Ex:
A A A
B B
C
n = int(input('Enter no of rows:'))#5
for i in range(n):#0,1,2,3,4
print((chr(65+i)+' ')*(n-i))
#__________________________________________________________________________________
# Write a program to print the following pattern. assume the number of rows is 5.
1. Use the While Loop
2. Use the Nested While Loop
3. Use For Loop
4. Use Nested For loop
Ex:
3 3 3
2 2
1
#__________________________________________________________________________________
# Write a program to print the following pattern. assume the number of rows is 5.
1. Use the While Loop
2. Use the Nested While Loop
3. Use For Loop
4. Use Nested For loop
Ex:
C C C
B B
A
#______________________________________________________________________________________________________________________
# Write a program to print the following pattern. assume the number of rows is 5.
1. Use the While Loop
2. Use the Nested While Loop
3. Use For Loop
4. Use Nested For loop
5 4 3 2 1
4 3 2 1
3 2 1
2 1
1
# Nested For Loop
n=5
#n = int(input('Enter no of rows:'))#5
for a in range(n,0,-1):
for b in range(a,0,-1):
print(b,end=' ' )
else:
print()
# Nested while Loop
n=5
a=1
while a<=n:
b=n
while b>=a:
print(b,end=' ')
b=b-1
print( )
a=a+1
#_______________________________________________________________________________________________________________________
# Write a program to print the following pattern. assume the number of rows is 5.
1. Use the While Loop
2. Use the Nested While Loop
3. Use For Loop
4. Use Nested For loop
Ex:
1 2 3
1 2
1
n=5
#n = int(input('Enter no of rows:'))#5
for a in range(1,n):
for b in range(1,n-a):
print(b,end=' ' )
else:
print()
n=5
a =1
#n = int(input('Enter no of rows:'))#5
while a <= n:
b=1
while b<=n-a:
print(b,end=' ' )
b = b+1
else:
print()
a = a +1
else:
pass
#__________________________________________________________________________________
# Write a program to print the following pattern. assume the number of rows is 5.
1. Use the While Loop
2. Use the Nested While Loop
3. Use For Loop
4. Use Nested For loop
Ex:
A B C
A B
A
#_______________________________________________________________________________________________________________________
# Write a program to print the following pattern. assume the number of rows is 5.
1. Use the While Loop
2. Use the Nested While Loop
3. Use For Loop
4. Use Nested For loop
Ex:
5 4 3 2 1
5 4 3 2
5 4 3
5 4
5
n=5
#n = int(input('Enter no of rows:'))#5
for a in range(5):
for b in range(n,a,-1):
print(b,end=' ' )
else:
print()
else:
pass
n=5
a=1
#n = int(input('Enter no of rows:'))#5
while a <= n:
b=n
while b>=a:
print(b,end=' ' )
b=b-1
else:
print()
a = a+1
else:
pass
#_______________________________________________________________________________________________________________________
# Write a program to print the following pattern. assume the number of rows is 5.
1. Use the While Loop
2. Use the Nested While Loop
3. Use For Loop
4. Use Nested For loop
Ex:
C B A
C B
C
#_______________________________________________________________________________________________________________________
# Write a program to print the following pattern. assume the number of rows is 5.
1. Use the While Loop
2. Use the Nested While Loop
3. Use For Loop
4. Use Nested For loop
n = 5
-------
* --->*'s (i+1), spaces:(n-i-1)
* *
* * *
* * * *
* * * * *
n = int(input('Enter n value:'))#5
for i in range(n):#0,1,2,3,4
print(' '*(n-i-1)+'* '*(i+1))
#_______________________________________________________________________________________________________________________
# Write a program to print the following pattern. assume the number of rows is 5.
1. Use the While Loop
2. Use the Nested While Loop
3. Use For Loop
4. Use Nested For loop
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
n = int(input('Enter n value:'))#5
for i in range(n):#0,1,2,3,4
print(' '*(n-i-1)+(str(i+1)+' ')*(i+1))
#_______________________________________________________________________________________________________________________
# Write a program to print the following pattern. assume the number of rows is 5.
1. Use the While Loop
2. Use the Nested While Loop
3. Use For Loop
4. Use Nested For loop
A
B B
C C C
D D D D
E E E E E
n = int(input('Enter n value:'))#5
for i in range(n):#0,1,2,3,4
print(' '*(n-i-1)+(chr(65+i)+' ')*(i+1))
#_______________________________________________________________________________________________________________________
# Write a program to print the following pattern. assume the number of rows is 5.
1. Use the While Loop
2. Use the Nested While Loop
3. Use For Loop
4. Use Nested For loop
n = 5
--------
* * * * *-------->spaces with i; *'s with (n-i)
* * * *
* * *
* *
*
n = int(input('Enter n value:'))#5
for i in range(n):#0,1,2,3,4
print(' '*i+'* '*(n-i))
#_______________________________________________________________________________________________________________________
# Write a program to print the following pattern. assume the number of rows is 5.
1. Use the While Loop
2. Use the Nested While Loop
3. Use For Loop
4. Use Nested For loop
Ex:
n = int(input('Enter n value:'))#5
for i in range(n):#0,1,2,3,4
print(' '*i+(str(i+1)+' ')*(n-i))
1 1 1 1 1
2 2 2 2
3 3 3
4 4
5
#_______________________________________________________________________________________________________________________
# Write a program to print the following pattern. assume the number of rows is 5.
1. Use the While Loop
2. Use the Nested While Loop
3. Use For Loop
4. Use Nested For loop
Ex:
n = int(input('Enter n value:'))#5
for i in range(n):#0,1,2,3,4
print(' '*i+(chr(65+i)+' ')*(n-i))
A A A A A
B B B B
C C C
D D
E
#_______________________________________________________________________________________________________________________
# Write a program to print the following pattern. assume the number of rows is 5.
1. Use the While Loop
2. Use the Nested While Loop
3. Use For Loop
4. Use Nested For loop
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*
n = int(input('Enter n value:'))#5
for i in range(n):
print(' '*(n-i-1)+'* '*(i+1))
for i in range(n-1):
print(' '*(i+1)+'* '*(n-i-1))
#_______________________________________________________________________________________________________________________
# Write a program to print the following pattern. assume the number of rows is 5.
1. Use the While Loop
2. Use the Nested While Loop
3. Use For Loop
4. Use Nested For loop
*
* *
* * *
* *
*
n = int(input('Enter n value:'))#5
for i in range(n):#0,1,2,3,4
print('* '*(i+1))
for i in range(n-1):
print('* '*(n-i-1))
#_______________________________________________________________________________________________________________________
# Write a program to print the following pattern. assume the number of rows is 5.
1. Use the While Loop
2. Use the Nested While Loop
3. Use For Loop
4. Use Nested For loop
Ex:
----
1
2 2
3 3 3
2 2
1
n = int(input('Enter n value:'))#5
for i in range(n):#0,1,2,3,4
print((str(i+1)+' ')*(i+1))
for i in range(n-1):
print((str(n-i-1)+' ')*(n-i-1))
#_______________________________________________________________________________________________________________________
# Write a program to print the following pattern. assume the number of rows is 5.
1. Use the While Loop
2. Use the Nested While Loop
3. Use For Loop
4. Use Nested For loop
Ex:
A
B B
C C C
B B
A
n = int(input('Enter n value:'))#5
for i in range(n):#0,1,2,3,4
print((chr(65+i)+' ')*(i+1))
for i in range(n-1):
print((chr(63+n-i)+' ')*(n-i-1))
#_______________________________________________________________________________________________________________________
# Write a program to print the following pattern. assume the number of rows is 5.
1. Use the While Loop
2. Use the Nested While Loop
3. Use For Loop
4. Use Nested For loop
n = 5
--------
*
* *------------->1 spaces --->i=1
* *------------>3 spaces --->i=2
* *----------->5 spaces --->i=3
* *---------->7 spaces --->i=4
n = int(input('Enter n value:'))#5
for i in range(n):#0,1,2,3,4
print(' '*(n-i-1)+'*',end='')
if i >= 1:
print(' '*(2*i-1)+'*',end='')
print()
#_______________________________________________________________________________________________________________________
Comments
Post a Comment