Functions



Exercise

1. Write a function called calculate_area that takes base and height as an input arguments and returns an area of a triangle as an output. Here is the equation for an area of a triangle,

Triangle Area = ½*base*height

2. Modify above function to take third parameter called shape type. Shape type could be either triangle or rectangle. Based on shape type it should calculate area. Equation for rectangle’s area is,

    Rectangle Area = length*width

If no shape is supplied then assume it to be triangle.

3. Write a function called print_pattern that takes integer number as argument and prints following pattern if input number is 3,

    *
    **
    ***

If input is 4 then it should print,
    *
    **
    ***
    ****

    Also if user doesn’t supply any argument then it should assume input to be 5.


Download Answers