I am creating a python program to check for a 7-digit social security number to tell the person's birthdate and gender in the format below: (I cannot use the datetime function).
For example, when the user enters a social security number(ex.1504084), the program will say their birth date and their gender. The last number '4' shows that the person is a female born after 2000(1: male born before 1999, 2: female born before 1999, 3: male born after 2000, 4: female born after 2000).
[Desired Output]
Enter your social registration number
>>> 1504084
You were born on **2015/04/08**
You are a female born after 2000
However, the line above in bold keep coming out as '1915/04/08.' Could anyone check my code below and tell me what I did wrong? Thanks in advance!
Here's my code:
YY = int(SSN[0:2])
MM = int(SSN[2:4])
DD = int(SSN[4:6])
G = int(SSN[6])
def yearcheck(G, YY): #년도 4자리수로 변환, G가 1,2일경우 1900~1999, 3,4일 경우 2000 이후
if G == 1 or 2:
return 1900 + YY
elif G == 3 or 4:
return 2000 + YY
else:
return False
#윤년인지 확인
def leapyear(YYYY):
if YYYY % 4 == 0:
return True
else:
return False
def monthcheck(MM):
if (MM > 0) and (MM < 13):
return True
else:
return False
def daycheck(SSN):
mgroup1 = [1,3,5,7,8,10,12]
mgroup2 = [4,6,9,11]
for m in mgroup1: #1-31일 사이
if MM == m:
if DD >=1 and DD <= 31:
return True
else:
return False
for m in mgroup2: #1-30일 사이 확
if MM == m:
if DD >=1 and DD <=30:
return True
else:
return False
if MM == 2:
# 윤년여부로 나누어 확인(윤년은 1-29일 사이, 윤년아닐경우 1-28일사이)
if leapyear(YYYY)==True:
if DD >=1 and DD <=29:
return True
else:
return False
else:
if DD >=1 and DD <=28:
return True
else:
return False
def valid_date_check(YY, MM, DD, G):
if yearcheck(G,YY) != False:
if monthcheck(MM)==True:
if daycheck(DD)==True:
return True
else:
False
else:
False
else: False
def SSN_print(YY,MM,DD,G,strdate):
if valid_date_check(YY,MM,DD,G)==True:
if SSN[6] == "1":
print("You were born on", strdate)
print("You are a male born between (1900-1999)")
elif SSN[6] == "2":
print("You were born on", strdate)
print("You are a female born between (1900-1999)")
elif SSN[6] == "3":
print("You were born on", strdate)
print("You are a male born after 2000")
elif SSN[6] == "4":
print("You were born on", strdate)
print("You are a female born after 2000")
else:
print('Invalid entry. Please enter a valid number')
else:
print('Invalid entry. Please enter a valid number')
YYYY = yearcheck(G, YY) #년도 4자리수
strYYYY= str(yearcheck(G, YY)) #최종표기용 string 년도
strdate = strYYYY+"/"+SSN[2:4]+"/"+SSN[4:6]
SSN_print(YY,MM,DD,G,strdate)