求助:关于python语句的结果表达形式!3)索引例子:编写日期索引,显示结果为月份 日期,年份.months=['1m','2m','3m','4m','5m','6m','7m','8m','9m','10m','11m','12m']endings=['st','nd','rd']+17*['th']\+['st','nd','rd']+7*[

来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/26 14:55:14
求助:关于python语句的结果表达形式!3)索引例子:编写日期索引,显示结果为月份日期,年份.months=[''1m'',''2m'',''3m'',''4m'',''5m'',''6m'',''7m'',''8m'',''9m''

求助:关于python语句的结果表达形式!3)索引例子:编写日期索引,显示结果为月份 日期,年份.months=['1m','2m','3m','4m','5m','6m','7m','8m','9m','10m','11m','12m']endings=['st','nd','rd']+17*['th']\+['st','nd','rd']+7*[
求助:关于python语句的结果表达形式!
3)索引例子:
编写日期索引,显示结果为月份 日期,年份.
months=['1m','2m','3m','4m','5m','6m','7m','8m','9m','10m','11m','12m']
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]
day_name=day+endings[day_number-1]
print month_name + '_'+day_name+'_,' +year
显示结果为:
year:2011
month(1~12):11
day(1~31):12
11m 12th ,2011
小白我唯一不太懂的地方就是print month_name + '_'+day_name+'_,' +year这行中, '_'+day_name+'_,'为啥加了那么多的单引号,而且day_name旁边还添加了+号,我尝试过去掉旁边的加号,但是显示出来的结果却是“11m day_name ,2011"
求各位大侠帮忙解答~~~!

求助:关于python语句的结果表达形式!3)索引例子:编写日期索引,显示结果为月份 日期,年份.months=['1m','2m','3m','4m','5m','6m','7m','8m','9m','10m','11m','12m']endings=['st','nd','rd']+17*['th']\+['st','nd','rd']+7*[
month_name + '_'+day_name+'_,' +year:采用+是将三个字符串和'_'一起连接成一个字符串.