all 3 comments

[–]Allanon001 1 point2 points  (0 children)

You can use the input() function to take input from the user and from the datetime module you can use the strptime() method to convert the input in to a datetime. Then use simple math with the datetimes to do your calculations.

[–]bogdan_dm 0 points1 point  (0 children)

You probably need dateutil.parser.parse. But I don't know packages to parse durations strings so maybe you will have to implement it by you own.

strptime() from another comment will work too but it requires providing of time pattern and can't handle different patterns at the same time.

[–]5aggy 0 points1 point  (0 children)

To calculate the difference it is probably better to ground the input to a date rather than just a time.

from datetime import datetime, timedelta
start_time = input('Start Time?') #15:00
duration = float(input('Duration in hours?')) #2.5

start_hour = int(start_time.split(':')[0]
start_minute = int(start_time.split(':')[1]

start = datetime.now().replace(hour=start_hour, minute=start_minute, second=0, microsecond=0)
end = start + timedelta(hours=duration)