Python 如何使我的条件检查不区分大小写?

Python 如何使我的条件检查不区分大小写?,python,Python,我的第一个Python程序从用户那里得到一个关于他生日的输入,并计算他或她是否18岁以上 如果字符串“check”等于true,则我的while循环将不会继续;它只适用于True。为什么不呢 import time import datetime check = "Null" year_born = month_born = day_born = 0 while check != "True": #or check!="true": year_born = input("wh

我的第一个Python程序从用户那里得到一个关于他生日的输入,并计算他或她是否18岁以上

如果字符串“check”等于
true
,则我的while循环将不会继续;它只适用于
True
。为什么不呢

import time
import datetime

check = "Null"
year_born = month_born = day_born = 0

while check != "True":
#or check!="true":
        year_born = input("what year were you born?")
        month_born = input("what month were you born?")
        day_born = input("what day were you born?")
        check = raw_input("your birth day is on {0}/{1}/{2}... type 'True' to confirme: ".format(day_born, month_born, year_born))

year_now = int(datetime.date.today().strftime("%Y"))
month_now = int(datetime.date.today().strftime("%m"))
day_now = int(datetime.date.today().strftime("%d"))

if (year_now - 18 > year_born) or (year_now - 18 == year_born and month_born <= month_now and day_born <= day_now):
        print("You are 18+. you are allowed to enter")

else: 
        print("Good bye")
导入时间
导入日期时间
check=“Null”
年出生=月出生=日出生=0
同时检查!=“正确”:
#或检查=“正确”:
year\u born=输入(“您出生的年份?”)
month\u born=输入(“您出生的月份?”)
day_born=输入(“您出生的日期?”)
check=raw_input(“您的出生日期在{0}/{1}/{2}…键入'True'以确认:“.format(day_born,month_born,year_born))
year\u now=int(datetime.date.today().strftime(“%Y”))
month\u now=int(datetime.date.today().strftime(“%m”))
day\u now=int(datetime.date.today().strftime(“%d”))

如果(year_now-18>year_born)或(year_now-18==year_born and month_born,请尝试使用规范化输入


您对while条件执行了一些奇怪的操作。请尝试
while check not in[“true”,“true”]:

为什么在注释的下一行有条件的第二部分?
while check.lower()!='true':
check=None
而不是
check=“Null”
Input返回一个字符串,因此
year\u born
等不是数字。您必须使用
int()
将它们转换为整数以执行减法运算。澄清一点:为什么要将布尔存储为字符串?您可以通过使用
check=False
然后在检查时使用
来简化它。
>>> 'True'.lower() == 'true'
True
>>> 'true'.lower() == 'true'
True
>>> 'TRUE'.lower() == 'true'
True