Functions
✕Functions Basics
Question 1 of 3
- Write a function
get_simple_interest(principal, rate, time)to calculate and return simple interest based on given principal, rate and time. - Write a function
get_rectangle_area_perimeter(length, width)to calculate and return area and perimeter of a rectangle based on length and width. - Write a function
is_palindrome(string)to check if a given string is palindrome or not. ReturnTrueif it is palindrome else returnFalse. - Write a function
count_vowels(string)return the number of vowels in a given string. - Write a function
get_square_root(num)to return the square root of a given number.
- Write a function
Using Functions
Question 2 of 3
- Write a lambda function to calculate cube of a number.
- Store
my_numas[1, 4, 7, 9, 12, 18]. Usedfilterfunction to select multiple of 3. - Store
my_numas[1, 4, 7]. Usedmapfunction to calculate cube of each number. - Store
my_numas[1, 5, 7, 9]. Usedreducefunction to calculate product of these. - Write a function
get_product_remainder(num_1, num_2)that returns product and remainder of two numbers - Write a function
sum_all()that takes n number of arguments and returns their sum. - Write a function
greet()that takes name of student and course enrolled. It has to return Hello, {name}, Welcome to {course} class. Note: If course is not passed it has to be Python in default
Function Challenge
Question 3 of 3
- You have a numbers stored in a list as
[1, -3, 0, 2, 0, 7, 10, 8, -1]. Write a functionget_data(l, r, x)that find the sum of number from position l to r. If 0 lies in that given range it has to be replaced by value x. Example: if l = 2, r = 6 and x = 5 then sum of item from position 2 to 6 is 19. Since there are two zeros replacing it by 5 gives: 19 + 5 + 5 i.e. 29 as output.
- You have a numbers stored in a list as
