CBSE Class 12 Computer Science
Question 97 of 103
Working with Functions — Question 3
Back to all questions 3
Question Write a program to have following functions :
(i) a function that takes a number as argument and calculates cube for it. The function does not return a value. If there is no value passed to the function in function call, the function should calculate cube of 2.
(ii) a function that takes two char arguments and returns True if both the arguments are equal otherwise False.
Test both these functions by giving appropriate function call statements.
# Function to calculate cube of a number
def calculate_cube(number = 2):
cube = number ** 3
print("Cube of", number, "is", cube)
# Function to check if two characters are equal
def check_equal_chars(char1, char2):
return char1 == char2
calculate_cube(3)
calculate_cube()
char1 = 'a'
char2 = 'b'
print("Characters are equal:", check_equal_chars(char1, char1))
print("Characters are equal:", check_equal_chars(char1, char2))Cube of 3 is 27
Cube of 2 is 8
Characters are equal: True
Characters are equal: False