badage = int("17")
goodage = int("18")
print("Check if you are eligible to vote in the United States")
users_age = int(input("How old are you?:"))
if users_age == badage :
print("You are ineligible to vote in the United States")
if users_age == goodage :
print("You are eligible to vote in the United States")
我想知道如何使它与18岁以下和18岁以上的每个数字的badage和goodage相同。
您可以使用<
和>
运算符:
if users_age < goodage:
print("You are ineligible to vote in the United States")
else:
print("You are eligible to vote in the United States")
试试这个代码:
badage = 17
goodage = 18
print("Check if you are eligible to vote in the United States")
users_age = input("How old are you?:")
if int(users_age) <= badage :
print("You are ineligible to vote in the United States")
else:
print("You are eligible to vote in the United States")