(Python)(Display four patterns using loops) Use nested loops that display the following patterns in four separate programs: *TUTOR INSTRUCTIONS* I have the code for all four patterns but for some reason the code is going downward instead of horizontally as shown in the provided image. Could you please just double check my coding and see how I can make it horizontal or if I need to seperate each pattern a certain way. The coding for this problem is: def numpat(n): # initialising starting number num = 1 # outer loop to handle number of rows for i in range(0, n): # re assigning num num = 1 # values changing acc. to outer loop for j in range(0, i + 1): print(num, end=" ") num = num + 1 # ending line after each row print("\r") n = 6 numpat(n) # iterate from 6 to 1 for i in range(6, 0, -1): # iterate from 1 to i+1 # since end value is exclusive, so adding 1 to i for j in range(1, i + 1): # print current value of j # set end to a space to print space after each value print(j, end=' ') # change the line after each iteration of outer loop print() n = 6 k = 2*n - 2 for i in range(0,n+1): for j in range(0,k+2): print(end=" ") k = k - 2 for j in range(1,i+1): print(i-j+1, end=" ") print() n = 6 for i in range(n, 0 , -1): for j in range(1, i + 1): print(j, end="") print('')
(Python)(Display four patterns using loops) Use nested loops that display the following patterns in four separate programs:
*TUTOR INSTRUCTIONS*
I have the code for all four patterns but for some reason the code is going downward instead of horizontally as shown in the provided image. Could you please just double check my coding and see how I can make it horizontal or if I need to seperate each pattern a certain way. The coding for this problem is:
def numpat(n):
# initialising starting number
num = 1
# outer loop to handle number of rows
for i in range(0, n):
# re assigning num
num = 1
# values changing acc. to outer loop
for j in range(0, i + 1):
print(num, end=" ")
num = num + 1
# ending line after each row
print("\r")
n = 6
numpat(n)
# iterate from 6 to 1
for i in range(6, 0, -1):
# iterate from 1 to i+1
# since end value is exclusive, so adding 1 to i
for j in range(1, i + 1):
# print current value of j
# set end to a space to print space after each value
print(j, end=' ')
# change the line after each iteration of outer loop
print()
n = 6
k = 2*n - 2
for i in range(0,n+1):
for j in range(0,k+2):
print(end=" ")
k = k - 2
for j in range(1,i+1):
print(i-j+1, end=" ")
print()
n = 6
for i in range(n, 0 , -1):
for j in range(1, i + 1):
print(j, end="")
print('')
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 8 images