棣小天儿的第一个python程序

python

根据给定的年月日,以数字形式打印出日期

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 = raw_input('Year: ')

month = raw_input('Month(1~12): ')

day = raw_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

Year: 2017
Month(1~12): 10
Day(1~31): 12
October 12th, 2017

以上是 棣小天儿的第一个python程序 的全部内容, 来源链接: utcz.com/z/386612.html

回到顶部