0% found this document useful (0 votes)
2 views2 pages

Nested Loops and Patterns in Python

Uploaded by

diwele8244
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Nested Loops and Patterns in Python

Uploaded by

diwele8244
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

# NESTED LOOP

# A loop (either for or while) inside (in body of) another loop

# Inner Loop is executed completely for each value of outer loop

for i in range(3): # Outer Loop (0,1,2)

for j in range(5): # Inner Loop (0,1,2,3,4)

print("Hello ",j)

print("END")

# When value of i is 0 j will run from 0 to 4

# When value of i is 1 j will run from 0 to 4

# When value of i is 2 j will run from 0 to 4

# Print 5 Hello in 3 row each

for i in range(3): # Outer Loop (0-2)

for j in range(5): # Inner Loop (0-4)

print("Hello ", end="")

print()

#WAP to input 2 numbers (Second number should be greater )

#and print table (first ten multiples) of all the numbers between those

n1=int(input("ENter First Number "))

n2=int(input("ENter Second Number, greater than first "))

for i in range (n1,n2+1):

for j in range (1,11):

print(i*j)

# Print the above in Following format

ENter First Number 3


ENter Second Number, greater than first 5
Table of 3
3 6 9 12 15 18 21 24 27 30
--------------------------------------------------
Table of 4
4 8 12 16 20 24 28 32 36 40
--------------------------------------------------
Table of 5
5 10 15 20 25 30 35 40 45 50
--------------------------------------------------
# Solution
n1=int(input("ENter First Number "))

n2=int(input("ENter Second Number, greater than first "))

for i in range (n1,n2+1):

print("Table of ",i)

for j in range (1,11):

print(i*j,end=" ")

print("\n", "-"*50)

# WAP to print following pattern

*
**
***
****
*****
for i in range (1,6):

print()

for j in range (1,i+1):

print("*",end=" ")

# WAP to print

1
22
333
4444
55555
for i in range (1,6):

print()

for j in range (1,i+1):

print(i,end=" ")

# WAP to print

55555

4444

333

22

You might also like