Ich verstehe nicht, warum dieser Code nicht funktioniert. Ich möchte einen Code erstellen, der mir hilft, genau zu wissen, wie viele Pillen zur Schmerztherapie zurückgebracht werden müssen. Wenn Sie nicht die richtige Menge zurück nehmen, werden Sie aus der Schmerztherapie entlassen. Ich möchte nur ein Skript erstellen, das mir hilft, also nehme ich nicht zu wenige zurück.Wie man eine Rezeptpillezahl herstellt, wie Schmerztherapieanlagen benutzen?
Wie jeder sagen kann. Ich habe keine Erfahrung mit Python. Ich habe es gerade installiert und versucht, die Dokumentation zu benutzen, um das zu vervollständigen, was ich für ein triviales Skript hielt.
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.")
"Wird nicht funktionieren" hilft nicht wirklich das Problem zu finden, sollten Sie die Frage bearbeiten, um den Fehler zu enthalten. Aber ich stelle mir vor 'total_pills = int (left_over_pill_count + new_prescription)' gibt Ihnen eine unbeabsichtigte Ausgabe. Sie müssen "int" an beiden Eingängen separat aufrufen, bevor Sie sie hinzufügen – roganjosh