2012-10-25 103 views
0

這和我最後一個問題很相似。但在這裏我想知道如何知道一個人是否可以做點什麼,例如:如何驗證生日是否通過?

如果joe小於21,他不允許喝酒,用生日告訴你他是否可以或不能。不使用導入或日曆,試圖得到它的掛鉤

到目前爲止,這是我想出的。

dateStr = input("Today's Date: ") 
monthStr, dayStr, yearStr = dateStr.split("/") 
months = ["January", "February","March", "April", "May", "June", "July", "August","September","October", "November","December"] 
monthStr = months[int(monthStr)- 1] 
print ("The converted date is:", monthStr, dayStr+",", yearStr) 
print("Joe did NOT have his birthday this year!") 
Joe's birthday = True 
for chr in dateStr: 
    tv = True 
    if: 
    (i<= 13) 
    print("Joe is Not allowed to watch TV.") 
    else: 
    print("Joe is allowed to watch TV.") 
driving = True 
if: 
    (i<= 16) 
    print("Joe is NOT Allowed to drive") 
else: 
    print("Joe is allowed to drive") 
    drinking = True 
if: 
    (i<= 21) 
    print("Joe is NOT allowed to drink.") 
else: 
    print("Joes is allowed to drink.") 
+0

人們可能會將生日轉換爲時間戳,並將其與時間戳進行比較,並將其與X年的秒數進行比較。 –

回答

5

我想這是一個任務,反正檢查出datetime模塊,它是生成和比較日期真的很方便。

0

這似乎是一個任務問題,你也應該簽出dateutil.parser,它可以自動轉換不同格式的日期,所以你不必自己解析它們。

相關問題