Computer Science
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.
Python
Python Functions
8 Likes
Answer
# 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))
Output
Cube of 3 is 27
Cube of 2 is 8
Characters are equal: True
Characters are equal: False
Answered By
2 Likes
Related Questions
Write a function that takes amount-in-dollars and dollar-to-rupee conversion price; it then returns the amount converted to rupees. Create the function in both void and non-void forms.
Write a function to calculate volume of a box with appropriate default values for its parameters. Your function should have the following input parameters :
(a) length of box ;
(b) width of box ;
(c) height of box.
Test it by writing complete program to invoke it.
Write a function that receives two numbers and generates a random number from that range. Using this function, the main program should be able to print three numbers randomly.
Write a function that receives two string arguments and checks whether they are same-length strings (returns True in this case otherwise False).