-1

I apologize if my question is a little confusing, because to be honest I am not 100% sure what I am trying to do either. I have a program that asks the user for a departure date and departure time, so I will end up with an input of something -like 2017-11-11 and 11:15 AM. The program then asks the user for an amount of miles they are going to travel and the speed in Miles Per Hour. So they might enter 300 for miles and 65 for MPH. I need to use this information to create an estimated arrival time, but I haven't the slightest clue how to do so. My program has no issue receiving this information, I just need to know how to work out the calculation.

Edit: Here is some sample of my code so it might be easier to understand what I am doing.

def get_departure_time():
while True:
    date_str = input("Enter departure time (HH:MM AM/PM): ")
    try:
        depart_time = datetime.strptime(date_str, "%H:%M %p")
    except ValueError:
        print("Invalid date format. Try again.")
        continue
    return depart_time

The function to get the departure date is the exact same, so using the user input for those two values, and the user input for miles and mph I have to create an arrival time.

  • 1
    Do you understand how to do it mathematically? I would recommend starting there and working the program up from that. As it stands this question is too broad and simply asking us to do your work for you. If you are only having problems converting a float to time (which is unclear) see: [this question](https://stackoverflow.com/questions/27496889/converting-a-float-to-hhmm-format) – LinkBerest Jul 13 '17 at 15:13
  • Have a look [here](http://physics.tutorvista.com/motion/speed.html). – Jeroen Heier Jul 13 '17 at 17:39

1 Answers1

0
num_hours = distance / mph
arrival_time = departure_time + num_hours

Not sure I understand your question, but is this what you're looking for?

zfisher
  • 61
  • 6
  • Thats essentially what I am trying to do, but I need to find a way to use modulo and Timedelta to actually add the time to the departure date and create the arrival date. – You Should Aim Jul 13 '17 at 15:22
  • `flight_time = timedelta(hours=num_hours)` and then you should be able to perform arithmetic with your `flight_time` object including modulus operations. You can reference the different representations of time like `flight_time.hours` or `flight_time.minutes`. – zfisher Jul 13 '17 at 15:54