我不明白爲什麼這段代碼不起作用。我想創建一些代碼來幫助我確切地知道需要將多少藥丸恢復到疼痛管理。如果你沒有把適量的錢拿回來,那麼你會被踢出痛苦管理。所以我只是想創建一個能夠幫助我的腳本,所以我不會回頭。如何創建像疼痛管理設施使用的處方藥計數?
正如任何人都可以說的。我對Python沒有任何經驗。我只是安裝它,並嘗試使用文檔來幫助完成我認爲是一個簡單的腳本。
Traceback (most recent call last):
File "C:\Users\howell\AppData\Local\Programs\Python\Python35-32\Scripts\pill_count.py", line 17, in <module>
date1 = datetime.date(datetime.strptime((str(year) + "-" + str(starting_Month) + "-" + str(starting_Month) + "-" + str(starting_Day)), '%Y-%m-%d'))
File "C:\Users\howell\AppData\Local\Programs\Python\Python35-32\lib\_strptime.py", line 510, in _strptime_datetime
tt, fraction = _strptime(data_string, format)
File "C:\Users\howell\AppData\Local\Programs\Python\Python35-32\lib\_strptime.py", line 346, in _strptime
data_string[found.end():])
ValueError: unconverted data remains: -1
How many pills did you have left? 12
How many pills did you get? 90
How many pills do you take? 6
Starting Month, Type 1 for January, 2 for February, etc.9
Starting Day; Type 1-311
Ending Month, Type 1 for January, 2 for February, etc.10
Starting Day; Type 1-3131
Taking 6 a day, you should have 102 left.
# 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(1, (date1-date2).days):
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.")
「無法正常工作」並不能真正幫助追蹤問題,您應該編輯問題以包含錯誤。但我想'total_pills = int(left_over_pill_count + new_prescription)'給你一個意想不到的輸出。在添加它們之前,需要分別在兩個輸入上調用'int' – roganjosh