0
2つの質問があります1_このフォームを使用することはできません05/04/2011私にエラーを与え続ける 2_ユーザーが負の数を使用するのをブロックできません。あなたがして使用することができ、日付のmm/dd/yyyy形式をPythonで検証する
def main():
# ask the user for a date as a string in the form mm/dd/yyyy
date = input("Please enter a date in form mm/dd/yyyy: ")
months, days, years = date.split("/")
# ask about the month
m = range(1,13)
months = m[eval(months)-1]
# april have only 30 days
if months in range(4,5):
D = range(1,31)
Days = D[eval(days)-1]
# june have only 30 days
elif months in range(6,7):
D = range(1,31)
Days = D[eval(days)-1]
# september have only 30 days
elif months in range(9,10):
D = range(1,31)
Days = D[eval(days)-1]
# november have only 30 days
elif months in range(11,12):
D = range(1,31)
Days = D[eval(days)-1]
# ask about days
d = range(1,32)
days = d[eval(days)-1]
# ask about the years
y = range(1,2017)
years = y[eval(years)-1]
if months <= 0:
print("you can't use a nagatve number")
if days <= 0:
print("you can't use negaive numbers")
if years <= 0:
print("you can't use negaiive numbers")
print(months,"/",days,"/",years,"is a valid date")
main()