如何让我的病情检查不区分大小写?

时间:2017-11-28 23:22:28

标签: python

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

如果字符串“check”等于from kivy.core.window import Window ... print("Window.size={}".format(Window.size)) print("Window.height={}".format(Window.height)) print("Window.width={}".format(Window.width)) ,我的while循环将不会继续;它只适用于true。为什么不呢?

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") while check != "True" or "true"以及while check != "True" or check != "true"。他们似乎都没有工作;它只是忽略“真实”和“真实”并保持循环。

2 个答案:

答案 0 :(得分:1)

尝试使用.lower()对输入进行规范化。

>>> 'True'.lower() == 'true'
True
>>> 'true'.lower() == 'true'
True
>>> 'TRUE'.lower() == 'true'
True

答案 1 :(得分:0)

你用while条件做了一些奇怪的事。试试while check not in ["true","True"]:

相关问题