-1

My first Python program gets an input from the user about his birthday and calculate if he or she is 18+.

My while loop won't continue if the string "check" is equal to true; it's only working for True. Why not?

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

I tried while check != "True" or "true" and while check != "True" or check != "true" and while ((check != "True") or (check != "true)). None of them seem to work; it's just ignoring "true" and "True" and keeps looping.

TylerH
  • 20,799
  • 66
  • 75
  • 101
HoThDo
  • 1
  • 2

2 Answers2

1

Try normalizing the input by using .lower().

>>> 'True'.lower() == 'true'
True
>>> 'true'.lower() == 'true'
True
>>> 'TRUE'.lower() == 'true'
True
Evan
  • 1,348
  • 2
  • 10
  • 20
0

You did something weird with the while conditional. Try while check not in ["true","True"]:

Jakob Lovern
  • 1,301
  • 7
  • 24