How to create a prescription pill count like pain management facilities use?
<p>I don't understand why this code won't work.  I want to create some code to help me know exactly how many pills need to be taken back to pain management.  If you don't take the right amount back, then you get kicked out of pain management.  So I'm just wanting to create a script that will help me so I don't take too few back.</p>

<p>As anyone can tell.  I don't have any experience with Python.  I just installed it and tried using the documentation to aide in completing what I thought would be a trivial script.</p>

<pre><code>Traceback (most recent call last):
  File "C:\Users\howell\AppData\Local\Programs\Python\Python35-32\Scripts\pill_count.py", line 17, in &lt;module&gt;
    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
</code></pre>



<pre><code>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.")
</code></pre>

<p>In this line:</p>

<pre><code>date1 = datetime.date(datetime.strptime((str(year) + "-" + str(starting_Month) + "-" + str(starting_Month) + "-" + str(starting_Day)), '%Y-%m-%d'))
</code></pre>

<p>You're telling <code>datetime.strptime</code> to parse a string of the form "year-month-day", but the string you give it is of the form "year-month-month-day"; you included the month twice!  The same problem applies to the next line as well.</p>

python