Computer Science
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:
*
**
***
Answer
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)
Output
Enter a number: 4
Pattern for input 4 :
*
**
***
****
Enter a number: 5
Pattern for input 5 :
*
**
***
****
*****
Related Questions
Write a function called calculate_area() that takes base and height as input arguments and returns area of a triangle as an output. The formula used is: Triangle Area = 1⁄2 * base * height
Modify the above function to take a third parameter called shape type. Shape type should be either triangle or rectangle. Based on the shape, it should calculate the area.
Formula used: Rectangle Area = length * widthWhat is the utility of : (i) default arguments, (ii) keyword arguments ?
Describe the different types of functions in Python using appropriate examples.