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

2024-10-03 06:21:59 发布

您现在位置:Python中文网/ 问答频道 /正文

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岁以上的每个数字都和坏的和好的一样


Tags: thetoinyouageifusersare
2条回答

请尝试以下代码:

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

您可以使用<>运算符:

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

相关问题 更多 >