おそらく起きていることを理解しています。条件は明らかに満たされていません。 i = 0〜bのようなもので、bは0またはnullに等しい。 9-01-2016と10-31-2016のように2つの日付の間の日数が必要です。だから61日でなければならない。私はforループを動かすのに助けが必要です
# dates are easily constructed and formatted
#from datetime import datetime, timedelta
from datetime import datetime
year = 2016
left_over_pill_count = input('How many pills did you have left? ')
new_prescription = input('How many pills did you get? ')
total_pills = int(left_over_pill_count) + int(new_prescription)
daily_pill_intake = input('How many pills do you take? ')
starting_Month = input('Starting Month, Type 1 for January, 2 for February, etc.')
starting_Day = input('Starting Day; Type 1-31')
ending_Month = input('Ending Month, Type 1 for January, 2 for February, etc.')
ending_Day = input('Starting Day; Type 1-31')
# count number of days until next doctors appointment
date1 = datetime.date(datetime.strptime((str(year) + "-" + str(starting_Month) + "-" + str(starting_Day)), '%Y-%m-%d'))
date2 = datetime.date(datetime.strptime((str(year) + "-" + str(ending_Month) + "-" + str(ending_Day)), '%Y-%m-%d'))
#date_count = (date2 - date1)
#total_days = date_count
# fmt = '%Y-%m-%d %H:%M:%S'
#fmt = '%d'
#d1 = datetime.strptime(date1, fmt)
#d2 = datetime.strptime(date2, fmt)
# print (d2-d1).days * 24 * 60
for i in range(date1.month, date2.month):
if (date1.month == 1):
for j in range(date1.day, 31):
total_pills = total_pills - int(daily_pill_intake)
if (date1.month == 2):
for j in range(date1.day, 28):
total_pills = total_pills - int(daily_pill_intake)
if (date1.month == 3):
for j in range(date1.day, 31):
total_pills = total_pills - int(daily_pill_intake)
if (date1.month == 4):
for j in range(date1.day, 30):
total_pills = total_pills - int(daily_pill_intake)
if (date1.month == 5):
for j in range(date1.day, 31):
total_pills = total_pills - int(daily_pill_intake)
if (date1.month == 6):
for j in range(date1.day, 30):
total_pills = total_pills - int(daily_pill_intake)
if (date1.month == 7):
for j in range(date1.day, 31):
total_pills = total_pills - int(daily_pill_intake)
if (date1.month == 8):
for j in range(date1.day, 31):
total_pills = total_pills - int(daily_pill_intake)
if (date1.month == 9):
for j in range(date1.day, 30):
total_pills = total_pills - int(daily_pill_intake)
if (date1.month == 10):
for j in range(date1.day, 31):
total_pills = total_pills - int(daily_pill_intake)
if (date1.month == 11):
for j in range(date1.day, 30):
total_pills = total_pills - int(daily_pill_intake)
if (date1.month == 12):
for j in range(date1.day, 31):
total_pills = total_pills - int(daily_pill_intake)
#for i in range(1, int(date1.day-date2.day)):
# total_pills = total_pills - int(daily_pill_intake)
# print(total_pills)
print("Taking " + str(daily_pill_intake) + " a day, you should have " + str(total_pills) + " left.")
にそれらを教えてください'2016-01-02'のような日付に入れば、あなたの人生ははるかに改善されます。 –
また、簡単な連結ではなく[文字列の書式設定](http://pyformat.info)を検討する必要があります。 –