輸入數字形式的年月日,輸出英文形式。

2022-07-09 10:06:09 字數 1057 閱讀 7523

months = ['january','february','march','april','may','june','july','august',

'september','october','november','december']

endings = ['st','nd','rd'] + 17 * ['th']+['st','nd','rd'] + 7 * ['th'] + ['st']

year = input('year: ')

month = input('month (1-12): ')

day = input('day(1-31): ')

month_number = int(month)

day_number = int(day)

month_name = months[month_number - 1]

ordinal = day + endings[day_number - 1]

print(month_name + '' + ordinal + ',' + year)

注:17*[th] 生成 乙個長度為17的列表,元素均為5261'th'。+,將列表合併成乙個大的列表。所以這行**的作用時生成乙個長度為31的字尾字元陣列。這樣就可以在day數字(1-31)後面 相應地加上字尾。如(1st, 2nd, 3rd, 4th, 5th, … , 19th, 20th, 21st, 22nd, 22rd, 23rd, 24th, … , 30th, 31st)。

endings=['st','nd','rd']+17['th']+['st','nd','rd']+7['th']+['st']

print endings

['st', 'nd', 'rd', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'st', 'nd', 'rd', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'st']

輸入年月日時分秒,輸出該年月日時分秒的下一秒

編寫乙個函式,要求輸入年月日時分秒,輸出該年月日時分秒的下一秒。如輸入2004年12月31日23時59分59秒,則輸出2005年1月1日0時0分0秒 考慮如何幾種情形 演算法思路 1 判斷現在月份是大月還是小月 大月 1月,3月,5月,7月,8月,10月,12月 31天 小月 2月 28天或者29天...

輸入年月日,輸出這個日期是今年的第多少天

typedef struct date date 判斷是否為閏年 bool isleapyear int year 計算總天數 inttotaldays struct date da arr儲存每個月的天數if isleapyear da year 判斷是否為閏年 一直迴圈到當前月份的上一月份 fo...

輸入年月日,判斷為該年的第幾天

程式設計基礎 c語言 楊莉 劉鴻翔 isbn 978 7 03 032903 5 p241 習題79.給出年 月 日,計算該日是該年的第幾天 include intdate count int int int 宣告計算函式 interror int int 宣告錯誤函式 intmain else p...