Computer Science
Find the errors in code given below :
define check()
N = input ('Enter N: ')
i = 3
answer = 1 + i ** 4 / N
Return answer
Python Functions
6 Likes
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
- 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. - 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
Answered By
3 Likes
Related Questions
Consider the code below and answer the questions that follow :
def multiply(number1, number2): answer = number1 * number2 return(answer) print(number1, 'times', number2, '=', answer) output = multiply(5, 5)
(i) When the code above is executed, what gets printed ?
(ii) What is variable output equal to after the code is executed ?
Find the errors in code given below :
def minus(total, decrement) output = total - decrement print(output) return (output)
Find the errors in code given below :
def alpha (n, string = 'xyz', k = 10) : return beta(string) return n def beta (string) return string == str(n) print(alpha("Valentine's Day"):) print(beta(string = 'true')) print(alpha(n = 5, "Good-bye"):)
Draw the entire environment, including all user-defined variables at the time line 10 is being executed.
1. def sum(a, b, c, d): 2. result = 0 3. result = result + a + b + c + d 4. return result 5. 6. def length(): 7. return 4 8. 9. def mean(a, b, c, d): 10. return float(sum(a, b, c, d))/length() 11. 12. print(sum(a, b, c, d), length(), mean(a, b, c, d))