Computer Science
Find the errors in the code given below:
define check()
N = input ( 'Enter N:'_
I = 3
Answer = 1 + i ** 4/N
Return answer
Python Functions
1 Like
Answer
The errors in the code are:
define check() #Error 1
N = input ('Enter N: ' #Error 2
I = 3
Answer = 1 + i ** 4 / N #Error 3
Return answer #Error 4
- The function definition lacks a colon at the end.
- 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. Parenthesis should be closed after input() function.
- In Python, variable names are case-sensitive. So if we define a variable as 'I', we should use it consistently as 'I' throughout code.
- The return statement should be in lowercase. If a variable is named 'Answer' (with an uppercase first letter), it should be used consistently with that casing throughout the program.
The corrected code is given below:
def check():
N = int(input('Enter N:'))
I = 3
Answer = 1 + I ** 4 / N
return Answer
Answered By
2 Likes
Related Questions
Predict the output of the following code:
a = 10 y = 5 def myfunc (a) : y = a a = 2 print ("y=",y, "a=", a) print ("a+y", a + y) return a + y print ("y=",y, "a=", a) print (myfunc (a)) print ("y=", y, "a=", a)
Find the errors in code given below :
def minus(total, decrement) output = total - decrement print(output) return (output)
Define flow of execution. What does it do with functions?
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.