0

I have a problem with multiple date conditions. If someone was born in 1911-1914 and he had a citizenship issued before 1922 it should be cancelled, otherwise they can keep it.

citizenship = datetime(year=1920, month=4, day=15)
dob = datetime(year=1910, month=5, day=5)

cit_start = datetime(year=1918, month=1, day=1)
cit_end = datetime(year=1922, month=12, day=31)
dob_start = datetime(year=1911, month=1, day=31)
dob_end = datetime(year=1914, month=12, day=31)

if not dob_start <= dob <= dob_end and not cit_start <= citizenship <= cit_end:
    print("keep it")
else:
    print("cancelled")

How could the resolution go to else only if both of the conditions are True?

1 Answers1

1

Write it the same way you said in the question, instead of trying to invert it:

if dob_start <= dob <= dob_end and cit_start <= citizenship <= cit_end:
    print("cancelled")
else:
    print("keep it")
Barmar
  • 741,623
  • 53
  • 500
  • 612