玩蛇网提供最新Python编程技术信息以及Python资源下载!

参照Python基础教程打印日期源码报NameError什么问题

代码如下
刚开始学python…可能描述的不清楚…

months = [
    'January'
          'February'
          'March'
          'April'
          'may'
          'June'
          'July'
          'September'
          'August'
          '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_nubmber = int(day) 
month_name = months[month_number-1]
ordinal = day + endings[day_number-1]
print month_name + ' ' + ordinal + ',' + year

----------------分割线----------------
回@lohocla4dam
我修改以后是这样的……
NameError: name 'day_number' is not defined

代码如下

months = [
'January',
      'February',
      'March',
      'April',
      'may',
      'June',
      'July',
      'September',
      'August',
      '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_nubmber = int(day)

month_name = months[month_number-1]
ordinal = day + endings[day_number-1]
print month_name + ' ' + ordinal + ',' + year

day_number 拼写错了 = =

day_nubmber 你拼错了吧。。。

你没有发现你给months赋值的时候少写了逗号吗。。。

题主试试这段代码就明白了

s = ['January'
     'February']

t = ['January',
     'February']

print(s, t)

玩蛇网文章,转载请注明出处和文章网址:https://www.iplaypy.com/wenda/wd19455.html

相关文章 Recommend

玩蛇网Python互助QQ群,欢迎加入-->: 106381465 玩蛇网Python新手群
修订日期:2017年05月22日 - 11时33分58秒 发布自玩蛇网

您现在的位置: 玩蛇网首页 > Python问题解答 > 正文内容
我要分享到:

必知PYTHON教程 Must Know PYTHON Tutorials

必知PYTHON模块 Must Know PYTHON Modules