Ex:
wap to display *’s in pyramid style or triangle shape
n=int(input("enter no of rows
"))
for i in range(1,n+1):
print(" "*(n-i),end="")
print("* "*i)
"""output:
enter no of rows 3
*
*
*
* * *
Nested Loops:
for i in range(2):
for j in range(2):
print(i,j)
"""output:
0 0
0 1
1 0
1 1
>>> """
for i in range(1,2):
for j in range(2):
print(i,j)
output:
1 0
1 1
>>>
#find out the output:
|
|
n=int(input("enter no of
rows:"))
for i in range(1,n+1):
for j in range(1,n+1):
print("*",end=" ")
print()
|
#find out the output:
n=int(input("enter no of
rows:"))
for i in range(1,n+1):
print("* " *i)
|
enter no of rows:3
*
* *
* * *
|
enter no of rows:3
*
* *
* * *
|
Related videos: https://www.youtube.com/watch?v=pPjwBlRRAWk&feature=youtu.be
Next Topic: Unconditional statements
Previous Topic: while loop
Nice examples. Thanks!
ReplyDeletePython Institute in Hyderabad