Hello! I'm fairly new to Python. Hopefully you can understand what I'm trying to accomplish here. I'm making a GUI that prints Parking Garage Tickets. I want to be able to post an expiration date on the ticket. I found out about timedelta, and it works if I put in, for example, datetime.timedelta(days=4). However, in my program, I have an entry box that allows the user to enter how many days they will be parking for. Is there a way to make timedelta accept a variable in between the parentheses? For example: timedelta(days=n), where n is the amount of days the user entered.

Here is what I have so far:

today = datetime.date.today()
        future = datetime.timedelta(days=4)
        expire = today + future
        date = Text(Point(250,185), expire)

If someone could please show me how to make it so that timedelta accepts a variable instead of a literal number? Thanks.. let me know if you need more information.

7 Years
Discussion Span
Last Post by jenzilla
import datetime
today = datetime.date.today()
time_to_stay = int(raw_input('Number of days you want to stay: '))
future = datetime.timedelta(days=time_to_stay)
expire = today + future
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.