Just beginning to learn python, read the book on the Code:
#根据给定的年月日以数字的形式打印出来
months = [
' January ',
' febuary ', '
March ',
' April ',
' may ',
' June ' ,
' July ',
' August ',
' September ',
' October ',
' November ',
' December '
]
The 1~31 number as the end of the list
endings = [' st ', ' nd ', ' Rd '] + * [' 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)
#记得要将月份和天数减1 to get the correct index
month_name = MONTHS[MONTH_NUMBER-1]
ordinal = day + endings[day_number-1]
print Month_name + ' + ordinal + ', ' + year
~
An error occurred while executing:
Syntaxerror:non-ascii character ' \xe6 ' in file print date. py on line 1, but no encoding declared; Http://www.python.org/peps/pep-0263.html for details
Baidu a bit:
The discovery is because Python does not support encoding in the source file in the default state. The solutions are as follows: three
First, add the following annotation code to the head of the file:
# coding=<encoding Name> For example, you can add a # Coding=utf-8
Second, add the following two lines of comment code to the head of the file:
#!/usr/bin/python
#-*-Coding: <encoding name>-*-For example, you can add #-*-Coding:utf-8-*-
Third, add the following two lines of comment code to the head of the file:
#!/usr/bin/python
# Vim:set fileencoding=<encoding name>: For example, you can add a # Vim:set Fileencoding=utf-8:
I used the first method to solve it. Record it.