Write a PYTHON program by using nested loop

Problem:

# Using python, write a program to show the following output depend on the value of input n.
# Sample input:
# 10
# Sample output:
# 1
# 1 2
# 1 2 3
# 1 2 3 4
# 1 2 3 4 5
# 1 2 3 4 5 6
# 1 2 3 4 5 6 7
# 1 2 3 4 5 6 7 8
# 1 2 3 4 5 6 7 8 9
# 1 2 3 4 5 6 7 8 9 10

Solution:

n = int( input())

for line in range(1,n+1,1):
for value in range(1,line+1,1):
print(value,end=” “)
print(“\n”)

Share

Leave a Reply

Your email address will not be published. Required fields are marked *

Proudly powered by WordPress | Theme: Lean Blog by Crimson Themes.