CBSE Class 12 Computer Science
Question 85 of 103
Working with Functions — Question 18
Back to all questionsThe errors in the code are:
def alpha (n, string = 'xyz', k = 10) :
return beta(string)
return n #Error 1
def beta (string) #Error 2
return string == str(n)
print(alpha("Valentine's Day"):) #Error 3
print(beta(string = 'true')) #Error 4
print(alpha(n = 5, "Good-bye"):) #Error 5- The second return statement in the
alphafunction (return n) is unreachable because the first return statementreturn beta(string)exits the function. - The function definition lacks colon at the end. The variable
nin thebetafunction is not defined. It's an argument toalpha, but it's not passed tobetaexplicitly. To accessnwithinbeta, we need to either pass it as an argument or define it as a global variable. - There should not be colon at the end in the function call.
- In the function call
beta(string = 'true'), there should be argument for parametern. - In the function call
alpha(n = 5, "Good-bye"), the argument "Good-bye" lacks a keyword. It should be string = "Good-bye".
The corrected code is given below:
def alpha(n, string='xyz', k=10):
return beta(string, n)
def beta(string, n):
return string == str(n)
print(alpha("Valentine's Day"))
print(beta(string='true', n=10))
print(alpha(n=5, string="Good-bye"))