Need some help with Time/Date calculations in Python 3 via /r/learnprogramming


Need some help with Time/Date calculations in Python 3

I am trying to make a program that asks the user for a time and date of departure, gets the amount of miles that are going to be traveled, miles per hour, and calculates an estimated time of arrival. I am at a good halfway point but I am lost on where to go from here. Any help is appreciated.

#!/usr/bin/env python3 # #Arrival Date/Time Estimator from datetime import datetime import locale mph = 0 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 def get_departure_date(): while True: date_str = input("Enter departure date (YYYY-MM-DD): ") try: depart_date = datetime.strptime(date_str, "%Y-%m-%d") except ValueError: print("Invalid date format. Try again. ") continue return depart_date def main(): print("Arrival Time Estimator\n") depart_time = get_departure_time() depart_date = get_departure_date() mph = input("Enter miles per hour ") miles = input("Enter miles: ") #arrival_date = depart_date+miles/mph #print (arrival_date) return if __name__ == "__main__": main() 

Submitted July 12, 2017 at 09:12PM by YouShouldAim
via reddit http://ift.tt/2tOrqNI

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s