如果用户的输入低于18,我如何让python对用户的输入做出回应?如果它超过18,还有别的吗

  • 本文关键字:如果 用户 回应 python python python-3.x
  • 更新时间 :
  • 英文 :

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")

相关内容

最新更新