Example:
num = int(input("Enter a number: ")) result = ["Even", "Odd"][num % 2] print(f"The number is {result}.")
Output:
Enter a number: 15 The number is Odd.
Example:
result = "Even" if int(input("Enter a number: ")) % 2 == 0 else "Odd" print(f"The number is {result}.")
Output:
Enter a number: 15 The number is Odd.
Example:
oddEven = lambda num:"Even" if num%2 == 0 else "Odd" # the lambda function number = int(input("Enter a number: ")) result = oddEven(number) print(f"The number is {result}.")
Output:
Enter a number: 15 The number is Odd.
Example:
class OddEvenChecker: def __init__(self, num): self.num = num def checkNumber(self): if self.num % 2 == 0: return "Even" else: return "Odd" # Using class nummber = int(input("Enter a number: ")) checker = OddEvenChecker(nummber) result = checker.checkNumber() print(f"The number is {result}.")
Output:
Enter a number: 15 The number is Odd.
Example:
num = int(input("Enter a number: ")) flag = False # Initialize the flag if num % 2 == 0: flag = True if flag: print("The number is Even") else: print("The number is Odd")
Output:
Enter a number: 15 The number is Odd.
Example:
num = int(input("Enter a number: ")) counter = 0 # Initialize the counter if num % 2 == 0: counter = 1 if counter: print("The number is Even") else: print("The number is Odd")
Output:
Enter a number: 15 The number is Odd.
Example:
num = int(input("Enter a number: ")) if num & 1: print("The number is Even") else: print("The number is Odd")
Output:
Enter a number: 15 The number is Odd.
Example:
num = int(input("Enter a number: ")) if num / 2 == num // 2: print("The number is Even") else: print("The number is Odd")
Output:
Enter a number: 15 The number is Odd.
Example:
num = int(input("Enter a number: ")) parity = ["Even", "Odd"] print(f"The number is {parity[num % 2]}.")
Output:
Enter a number: 15 The number is Odd.
Example:
num = int(input("Enter a number: ")) parity = {0: "Even", 1: "Odd"} print(f"The number is {parity[num % 2]}.")
Output:
Enter a number: 15 The number is Odd.
Example:
def isEven(n): if n == 0: return True if n == 1: return False return isEven(n - 2) num = int(input("Enter a number: ")) if isEven(num): print("The number is Even") else: print("The number is Odd")
Output:
Enter a number: 15 The number is Odd.
Example:
num = int(input("Enter a number: ")) result = ["Even", "Odd"][num % 2] print(f"The number is {result}.")
Output:
Enter a number: 15 The number is Odd.