Question

In: Computer Science

Need the following program in Python: Create a program that calculates the estimated duration of a...

Need the following program in Python:

Create a program that calculates the estimated duration of a trip in hours and minutes. This should include an estimated date/time of departure and an estimated date/time of arrival.

Arrival Time Estimator

Enter date of departure (YYYY-MM-DD): 2016-11-23

Enter time of departure (HH:MM AM/PM): 10:30 AM

Enter miles: 200

Enter miles per hour: 65

Estimated travel time

Hours: 3

Minutes: 5

Estimated date of arrival: 2016-11-23

Estimated time of arrival: 01:35 PM

Continue? (y/n): y

Enter date of departure (YYYY-MM-DD): 2016-11-29

Enter time of departure (HH:MM AM/PM): 11:15 PM

Enter miles: 500

Enter miles per hour: 80

Estimated travel time Hours: 6

Minutes: 20

Estimated date of arrival: 2016-11-30

Estimated time of arrival: 05:35 AM

Continue? (y/n): n Bye!

Specifications

  • For the date/time of departure and arrival, the program should use the YYYY-MM- DD format for dates and the HH:MM AM/PM format for times.
  • Create a single data/time string variable based on the two input variables. Use this combined string variable to create a departure date-time object that will be used to determine the estimated arrival date and time.
  • For the miles and miles per hour, the program should only accept integer entries like 200 and 65.
  • Calculate the hours travelled based on the integer division of miles divided by mph. The minutes are based on the remainder of miles divided by mph. The remainder must then be converted to minutes based on the mph.
  • Assume that the user will enter valid data.

Solutions

Expert Solution

Please find the Code as below:

#Importing the datetime classes

import datetime
from datetime import date, time
from datetime import datetime
from datetime import timedelta

print("Arrival Time Estimator")
dep_dt = input("Enter date of departure (YYYY-MM-DD): ")
dep_time = input("Enter time of departure (HH:MM AM/PM): ")

#Combine String to get the Departure Date and Time

departure_date = dep_dt + " " + dep_time

#Use of strptime method to convert the 'departure_date' string into Date object with 12 Hr format

dep_date_obj = datetime.strptime(departure_date, '%Y-%m-%d %I:%M %p')

miles = int(input("Enter miles: "))
miles_ph = int(input("Enter miles per hour: "))
print("Estimated travel time")

#Calculating 'Hours' and 'Minutes' using the 'miles' and 'miles per hour' values

hours = miles//miles_ph
minutes = round(((miles/miles_ph)*60)%60)
print("Hours : ", hours)
print("Minutes : ", minutes)

#Adding the calculated Hours and Minutes with the dep_date_obj using the in-built function timedelta

arr_dt_obj = dep_date_obj + timedelta(hours=hours,minutes=minutes)

#Converting the arr_dt_obj to string using strftime method in 12 Hr format

arrival_date = datetime.strftime(arr_dt_obj, '%Y-%m-%d %I:%M %p')
print("Estimated date of arrival: ", arrival_date[:-8])
print("Estimated time of arrival: ", arrival_date[11:])

Please refer the below code screenshot for the better understanding of Indentations:

Sample Output:


Related Solutions

Which of the following is true about duration and modified duration? I. The Macaulay duration calculates...
Which of the following is true about duration and modified duration? I. The Macaulay duration calculates the weighted average time before a bondholder would receive the bond's cash flows. II. Modified duration measures price sensitivity of a bond to changes in YTM by adjusting duration with a factor based on current yield. III. The value of duration and modified duration are usually very close, but duration is almost always a larger number.A.Duration is important to banks when they try to...
Create a Python script in IDLE or Kali Python3 CLI to create the following Python Program:...
Create a Python script in IDLE or Kali Python3 CLI to create the following Python Program: Your program will create a username of your choice using a Kali Linux command "useradd -m mark", then set the password for that user using the Kali Linux Command "echo "mark:10101111" | chpasswd". Then you create a dictionary file using the Kali Linux command "crunch 8 8 01 > mylist.txt" Your python script should crack the password for that user and display on the...
hello, I need a python program for a drone to follow keyboard commands - Create a...
hello, I need a python program for a drone to follow keyboard commands - Create a simple single obstacle environment and program the drone to navigate through it - Create a more advanced obstacle environment (3+ obstacles) and program the drone to navigate through it
IN PYTHON create a python program that accepts input from the user in the following sequence:...
IN PYTHON create a python program that accepts input from the user in the following sequence: 1. Planet Name 2. Planet Gravitational Force(g) for data, use the planets of our solar system. The data input is to be written in 2 separate lists, the names of which are: 1. planetName 2. planet GravitationalForce(g) A third list is required that will store the weight of a person with mass of 100kg, the formula of which is: W=mg(where m is mass of...
Create a program in java that calculates area and perimeter of a square - use a...
Create a program in java that calculates area and perimeter of a square - use a class and test program to calculate the area and perimeter; assume length of square is 7 ft.
Create a python code that calculates fixed point iteration method using a for loop.
Create a python code that calculates fixed point iteration method using a for loop.
In Python write a program that calculates and prints out bills of the city water company....
In Python write a program that calculates and prints out bills of the city water company. The water rates vary, depending on whether the bill is for home use, commercial use, or industrial use. A code of r means residential use, a code of c means commercial use, and a code of i means industrial use. Any other code should be treated as an error. The water rates are computed as follows:Three types of customers and their billing rates: Code...
Write a python program that calculates the average number of words per sentence in the input...
Write a python program that calculates the average number of words per sentence in the input text file. every sentence ends with a period (when, in reality, sentences can end with !, ", ?, etc.) and the average number of sentences per paragraph, where a paragraph is any number of sentences followed by a blank line or by the end of the text.
In C Program #include Create a C program that calculates the gross and net pay given...
In C Program #include Create a C program that calculates the gross and net pay given a user-specified number of hours worked, at minimum wage. The program should compile without any errors or warnings (e.g., syntax errors) The program should not contain logical errors such as subtracting values when you meant to add (e.g., logical errors) The program should not crash when running (e.g., runtime errors) When you run the program, the output should look like this: Hours per Week:...
Create the pseudocode solution to a program that calculates the final score and letter grade for...
Create the pseudocode solution to a program that calculates the final score and letter grade for one student. Please use the following grading system: 9 Homework Assignments – 100 points each 10 points 11 Quizzes – 100 points each 5 points 5 Projects – 100 points each 10 points 6 Discussion posts – 100 points each 10 points 4 Exams – 100 points each 65 points A = 90 – 100% B = 80 – 89% C = 70 –...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT