CBSE Class 12 Computer Science Question 84 of 103

Working with Functions — Question 17

Back to all questions
17
Question

Question 12(b)

Find the errors in code given below :

define check()
    N = input ('Enter N: ') 
    i = 3                                             
    answer = 1 + i ** 4 / N                              
    Return answer       
Answer

The errors in the code are:

define check() #Error 1
    N = input ('Enter N: ') #Error 2
    i = 3                                             
    answer = 1 + i ** 4 / N                              
    Return answer #Error 3
  1. The function definition lacks a colon at the end.
  2. The 'input' function returns a string. To perform arithmetic operations with N, it needs to be converted to a numeric type, such as an integer or a float.
  3. The return statement should be in lowercase.

The corrected code is given below:

def check():
    N = int(input('Enter N:'))
    i = 3
    answer = 1 + i ** 4 / N
    return answer