mardi 19 octobre 2021

In the below Question the print statement is only supposed to give as VALID or INVALID but sometimes it gives string other than that. Can someone expl [closed]

import re 
a=input()
if re.match("[0-3][0-9]-[0-1][0-9]-[0-2][0-9][0-9][0-9]",a):
    b=int(a[6:10])
    if b%4==0:
        c=int(a[3:5])
        if c==1 or c==3 or c==5 or c==7 or c==8 or c==10 or c==12:
            d=int(a[0:2])
            if d<32:
                print("VALID")
            else:
                print("IN VALID")
        elif c==4 or c==6 or c==9 or c==11 :
            d=int(a[0:2])
            if d<31:
                print("VALID")
            else:
                print("IN VALID")
        elif c==2:
            d=int(a[0:2])
            if d<30:
                print("VALID")
            else:
                print("IN VALID")
        else:
            print("IN VALID")
    else:
        c=int(a[3:5])
        if c==1 or c==3 or c==5 or c==7 or c==8 or c==10 or c==12:
            d=int(a[0:2])
            if d<32:
                print("VALID")
            else:
                print("IN VALID")
        elif c==4 or c==6 or c==9 or c==11 :
            d=int(a[0:2])
            if d<31:
                print("VALID")
            else:
                print("IN VALID")
        elif c==2:
            d=int(a[0:2])
            if d<29:
                print("VALID")
            else:
                print("IN VALID")
        else:
            print("IN VALID")
else:
    print("IN VALID")

##had written this coded in python to verify if a date given as a input is valid or not including leap year. Because I just started learning python this was the only way i could think to solve it. it works fine for most dates but when i input some particular values i get this as my answer Output with varying degree of correctness

I don't know how it is being printed as in print statement only ("VALID") or ("Invalid") is given.Can someone please explain where it goes wrong.

Aucun commentaire:

Enregistrer un commentaire