age = int(input("Enter your age: "))
if not (age >= 18):
print("You are NOT eligible to vote.")
else:
print("You are eligible to vote.")
#source code --> clcoding.com
Code Explanation:
Taking Input from the User
age = int(input("Enter your age: "))
The program asks the user to enter their age.
input() returns a string, so we use int() to convert it to an integer and store it in the variable age.
Checking Eligibility with not Operator
if not (age >= 18):
age >= 18 checks if the person is eligible to vote (18 or older).
not (age >= 18) negates the condition:
If age is 18 or more, age >= 18 is True, and not True becomes False.
If age is less than 18, age >= 18 is False, and not False becomes True.
Printing the Result
print("You are NOT eligible to vote.")
If not (age >= 18) is True (meaning the person is under 18), the program prints:
"You are NOT eligible to vote."
else:
print("You are eligible to vote.")
If the condition is False (meaning the person is 18 or older), the program prints:
"You are eligible to vote."
0 Comments:
Post a Comment