[Tutor] Future Appointments...

Robert Berman bermanrl at cfl.rr.com
Sun Jan 31 20:34:30 CET 2010



-----Original Message-----
From: tutor-bounces+bermanrl=cfl.rr.com at python.org
[mailto:tutor-bounces+bermanrl=cfl.rr.com at python.org] On Behalf Of Ken G.
Sent: Sunday, January 31, 2010 10:41 AM
To: tutor at python.org
Subject: [Tutor] Future Appointments...

Below is a program to determine when my next appointment is.  Line 
numbers are provided for reference only.

01  import time, datetime, sys
02  from datetime import date
03  today = date.today()
04  print
05  print "Today date is:", today
06  todaystr = str(today)
07  print
08  print "Corrected date format is:",
09  print todaystr[ 5: 7], todaystr[ 8:10], todaystr[ 0: 4]
10  print
11  future = raw_input("Next appointment is in how many days?  "),
12  print
13  difference1 = datetime.timedelta(days=1)
14  datestring = str(today + difference1)
15  print "Next appointment after that is:",datestring
16  print
17  print "Corrected date format for next appointment is:",
18  print datestring[ 5: 7], datestring[ 8:10], datestring[ 0: 4]
19  sys.exit()

In answering the question in line 11 as to when is my next appointment, 
I would answer "3" (for 2/3/2010) but how do I change "days=1" at end of 
line 13 to "days=3" so that datestring would read "2010-02-03" instead 
of "2010-02-01" as presented above?

TIA,

Ken
*****************************************************************

Hi Ken,

I slightly altered your program. I think this is what you asked for. It will
work for n number of days; for example, 1, 10, 45, 118, 412 work nicely.

See code here: http://pastebin.com/m6e78d3ce

Robert



More information about the Tutor mailing list