Computer Science
Write a function that receives two string arguments and checks whether they are same-length strings (returns True in this case otherwise False).
Python
Python Functions
8 Likes
Answer
def same_length_strings(str1, str2):
return len(str1) == len(str2)
s1 = "hello"
s2 = "world"
s3 = "python"
print(same_length_strings(s1, s2))
print(same_length_strings(s1, s3))
Output
True
False
Answered By
5 Likes
Related Questions
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.
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 namely nthRoot( ) that receives two parameters x and n and returns nth root of x i.e., x^(1/n).
The default value of n is 2.Write a function that takes a number n and then returns a randomly generated number having exactly n digits (not starting with zero) e.g., if n is 2 then function can randomly return a number 10-99 but 07, 02 etc. are not valid two digit numbers.