[英]I don't understand why i can't get readline function in python to work in this program. What am I doing wrong?
[英]Spotify Best Before program. What am I doing wrong?
我想回答這個問題的Spotify 前最佳和我的代碼可以正確處理每一個測試用例我能想到的。 但是,根據他們的服務器,我錯了。
誰能告訴我我的代碼哪里出錯了?
這是我的代碼:
from itertools import permutations
import datetime
import fileinput
def checkdate(d,m,y):
"""Gets possible values for day, month and year
and generates valid permutations of dates"""
b = permutations([d,m,y])
for p in b:
try:
yield datetime.date(p[0], p[1], p[2])
except ValueError:
yield None
def validvalue(a):
return a > 0 and a <= 2999
c = raw_input()
d,m,y = c.split('/')
d,m,y = int(d), int(m), int(y)
if validvalue(d) and validvalue(m) and validvalue(y):
valid = [x for x in checkdate(d,m,y) if x is not None]
if valid:
print "2" + str(min(valid))[1:]
else:
print "%s is illegal" % c
else:
print "%s is illegal" % c
從問題描述:
2000可以指定為“ 2000”,“ 00”或“ 0”
您的代碼不接受00
或0
作為有效年份。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.