There is one single line contains the day number d, month name M and year number y(1000≤y≤3000). The month name is the corresponding English name starting from the capital letter.
Output a single line with the English name of the day of week corresponding to the date, starting from the capital letter. All other letters must be in lower case. Month and Week name in Input/Output: January, February, March, April, May, June, July, August, September, October, November, December Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
9 October 2001 14 October 2001
Tuesday Sunday
import datetime
while True:
try:
month = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October',
'November', 'December']
week = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
d, m, y = input().split()
print(week[int(datetime.datetime(int(y), month.index(m) + 1, int(d)).strftime("%w"))])
except:
break
看了下面的答案后,发现还可以更简单,"A"直接输出的是Tuesday这种格式,太方便了。于是代码可以缩成三行:
import datetime
while True:
try:
month = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October','November', 'December']
d, m, y = input().split()
print((datetime.datetime(int(y), month.index(m) + 1, int(d)).strftime("%A")))
except:
break
人生苦短,我爱python。
from datetime import datetime Month = {'May': 5, 'December': 12, 'October': 10, 'August': 8, 'July': 7, 'February': 2, 'January': 1, 'September': 9, 'March': 3, 'April': 4, 'November': 11, 'June': 6} try: while 1: k = raw_input().split() print datetime(int(k[2]),Month[k[1]],int(k[0])).strftime('%A').capitalize() except: pass