Code Explanation:
def check_even_odd(n):
Defines a function named check_even_odd that takes one parameter, n.
n is expected to be an integer.
The function will determine whether n is even or odd.
return "Even" if n % 2 == 0 else "Odd"
This single line uses a ternary conditional operator (a shorthand if-else statement).
Condition: n % 2 == 0 checks if the number n is divisible by 2.
If the remainder when n is divided by 2 is 0, the condition is True, and the function returns "Even".
If the condition is False, it returns "Odd".
print(check_even_odd(4))
Calls the check_even_odd function with the argument 4.
The function evaluates whether 4 is even or odd and returns the string "Even".
The print() function outputs the returned value ("Even") to the console.
Output:
When you run this corrected code, the output will be:
Even
0 Comments:
Post a Comment