The following program is supposed to display a message indicating if the integer entered by the user is even or odd. What is wrong with the program?
num = int(input("Enter an integer: "))
print("The integer is", evenOdd(num))
def evenOdd(n) :
if n % 2 == 0 :
return "even"
return "odd"
A. The function definition must appear before the function is called.
B. The input and print statements must reside in a function named main.
C. The variable num and the parameter variable n must have the same name.
D. An else clause must be added to the if statement.

Respuesta :

Answer:

A. The function definition must appear before the function is called

Explanation:

Given

The above lines of code

Required

Determine the error in the program

In python, functions has be defined before they are called but in this case (of the given program), the function is called before it was defined and this will definitely result in an error;

Hence, option A answers the question

The correct sequence of the program is as follows:

def evenOdd(n):

     if n % 2 == 0:

           return "even"

     return "odd"

num = int(input("Enter an integer: "))

print("The integer is", evenOdd(num))

ACCESS MORE