CBSE Class 11 Computer Science
Question 59 of 98
Python Programming Fundamentals — Question 21
Back to all questions 21
Question Write a function called print_pattern() that takes integer number as argument and prints the following pattern if the input number is 3:
*
* *
* * *
If input is 4, then it should print:
*
* *
* * *
* * * *
def print_pattern(num):
for i in range(1, num + 1):
print("*" * i)
num = int(input("Enter a number: "))
print("Pattern for input", num, ":")
print_pattern(num)Enter a number: 4
Pattern for input 4 :
*
**
***
****
Enter a number: 5
Pattern for input 5 :
*
**
***
****
*****