0
나는 모든이 정말 새로 온 사람과 지금은 두 가지 기능을 수행하고 인쇄하려고 노력하고있어,하지만 난 그것을 이해 할 수없는 것 :파이썬에서 두 함수를 동시에 사용하려면 어떻게해야합니까?
import datetime
def get_date(prompt):
while True:
user_input = raw_input(prompt)
try:
user_date = datetime.datetime.strptime(user_input, "%m-%d")
break
except Exception as e:
print "There was an error:", e
print "Please enter a date"
return user_date.date()
def checkNight(date):
date = datetime.strptime('2011-'+date, '%Y-%m-%d').strftime('$A')
birthday = get_date("Please enter your birthday (MM-DD): ")
another_date = get_date("Please enter another date (MM-DD): ")
if birthday > another_date:
print "Your friend's birthday comes first!"
print checkNight(date)
elif birthday < another_date:
print "Your birthday comes first!"
print checkNight(date)
else:
print "You and your friend can celebrate together."
수 있어야 get_date
기능 날짜가 5 자인지 확인하고 분할이 무엇이든 허용합니다. 또한 누군가가 "02-29"를 입력하면 "02-28"로 취급 할 것입니다. checkNight
은 이전 생일이 어느 날 밤에 있는지 확인할 수 있어야합니다.
은 몇 가지 예이다 :
Please enter your birthday (MM-DD): 11-25 Please enter a friend's birthday (MM-DD): 03-05 Your friend's birthday comes first! Great! The party is on Saturday, a weekend night. Please enter your birthday (MM-DD): 03-02 Please enter a friend's birthday (MM-DD): 03-02 You and your friend can celebrate together! Too bad! The party is on Wednesday, a school night. Please enter your birthday (MM-DD): 11-25 Please enter a friend's birthday (MM-DD): 12-01 Your birthday comes first! Great! The party is on Friday, a weekend night.
코드에 표현하고 있지만 표현할 수없는 것을 적어 두십시오. 그것 없이는, 그것은 질문이 아니라 작업 묘사입니다. –
파이썬 튜토리얼을 사용하면 http://wiki.python.org/moin/BeginnersGuide/Programmers를 시작할 수 있습니다. – MattiaG