A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Print the following number pattern using python programming
Q:

Print the following number pattern using python programming

0

Print the following number pattern

1 1 1 1 1 
2 2 2 2 
3 3 3 
4 4 
5

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Hint:

  • set x = 0
  • Use two for loops
  • The outer loop is reverse for loop from 5 to 0
  • Increment value of x by 1 in each iteration of an outer loop
  • The inner loop will iterate from 0 to the value of i of the outer loop
  • Print value of x in each iteration of an inner loop
  • Print newline at the end of each outer loop

Solution:

rows = 5
x = 0
# reverse for loop from 5 to 0
for i in range(rows, 0, -1):
    x += 1
    for j in range(1, i + 1):
        print(x, end=' ')
    print('\r')

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now