def even_odd_decimal(num): if num%1!=0: return num "is decimal" elif num%2==0: return num "is even" else: return num "is odd"
Question
def even_odd_decimal(num):
if num % 1 != 0:
return num "is decimal"
elif num % 2 == 0:
return num "is even"
else:
return num "is odd"
Solution
The function even_odd_decimal(num)
is intended to check if a number is decimal, even or odd. However, there are some syntax errors in the function. Here is the corrected version:
def even_odd_decimal(num):
if num % 1 != 0:
return str(num) + " is decimal"
elif num % 2 == 0:
return str(num) + " is even"
else:
return str(num) + " is odd"
Here's how it works:
- The function takes a number as an argument.
- It first checks if the number is a decimal by checking if the remainder of the division of the number by 1 is not equal to 0. If it is a decimal, it returns a string stating that the number is decimal.
- If the number is not a decimal, it checks if the number is even by checking if the remainder of the division of the number by 2 is equal to 0. If it is even, it returns a string stating that the number is even.
- If the number is neither a decimal nor even, it means the number is odd. So, it returns a string stating that the number is odd.
Similar Questions
If num is an integer variable, what does the expression num % 2 == 0 ? "Even" : "Odd" represent?
Read a number from the user. Check whether it is odd or even using lambda function and print the output as either ODD or EVEN. Sample Input5Sample OutputODD
Even numbersWrite a Python program to print the even numbers from a list.Sample Test Cases
Question 2If var = “01234567” what Python statement would print out only the even elements?1 pointprint(var[::1])print(var[::3])print(var[::2])
A simple, and useful formula, ________ tells you if the value in a cell is odd or even.=ODD=ISODD=ISEVEN
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.