|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- # Print out a date, given year, month, and day as numbers
- months = [
- 'January',
- 'February',
- 'March',
- 'April',
- 'May',
- 'June',
- 'July',
- 'August',
- 'September',
- 'October',
- 'November',
- 'December'
- ]
- # A list with one ending for each number from 1 to 31
- 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)
- # Remember to subtract 1 from month and day to get a correct index
- month_name = months[month_number-1]
- ordinal = day + endings[day_number-1]
- print(month_name + ' ' + ordinal + ', ' + year)
复制代码
- RESTART: /Users/Yuan_YangXin/Desktop/beginning-python-3ed-master/Chapter02/listing2-1.py
- Year: 1974
- Month (1-12): 8
- Day (1-31): 16
- Traceback (most recent call last):
- File "/Users/Yuan_YangXin/Desktop/beginning-python-3ed-master/Chapter02/listing2-1.py", line 32, in <module>
- ordinal = day + endings[day_number-1]
- TypeError: unsupported operand type(s) for +: 'int' and 'str'
复制代码
你用的是python2?
如果是的话,把input改为raw_input
|
|