2017-03-15 39 views
0

我需要使用spyder使用元組轉換時間和日期。元組使用時間和日期與元組

它就是這樣def problem3_3(month, day, year)。寫一個將日期從一種格式轉換爲另一種格式的函數。

具體而言,06/10/2016應轉換爲June 17, 2016。其實,你 將輸入的6,17,和2016年作爲獨立的整數(numbers)和 功能將組裝和打印日期爲6月17日,2016年

我建議你創建一個tuple months = ("January", "February", "March", ...)到 商店月份的名字。 然後很容易獲得名稱二月 爲months[1]等等.. 請幫助。感謝

+0

謝謝先生,但我可以串聯怎麼樣,因爲它給了我這個錯誤(類型錯誤:只能拼接元組(而不是「STR」),以數組)[解析日期字符串並更改格式的 –

+0

可能的複製](http://stackoverflow.com/questions/2265357/parse-date-string-and-change-format) – Juggernaut

回答

0
def problem3_3(month, day, year): 
""" Takes date of form mm/dd/yyyy and writes it in form June 17, 2016 
    Example3_3: problem3_3(6, 17, 2016) gives June 17, 2016 """ 
months=("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December") 

for month in months: 

    #print (month[5] +" "+str(day)+", "+str(year)) 
    print (months[month-1] +" "+ str(day)+", "+ str(year))