Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Geese
#1
I am stuck on the following problem at college. I have just begun learning python and have made a first attempt at solving this problem. Working out the distance traveled and the amount of time taken is of course very simple but my trouble is with working out how I can use 24 hour time accurately. How can I limit a 4 digit input or output so that the first two digits range from 00 - 24 and the 2nd two digits range from 0 - 60? Very confused, not looking for a direct solution as I'd like to solve it myself but some direction on how to begin might be helpful. I'm also aware that a lot of the variables I have defined are not strictly necessary, I just wrote them there as I worked them out in case they were helpful later. Thanks in advance.

Canada goose migrations can be as long as 2,000 to 3,000 miles, and the geese are capable of flying up to 1,500 miles in a single day.

If a flock of geese leave Edinburgh and travel at an average speed of 50mph. They stop in Iceland for 12 hours which is 805 miles away and then travel a farther 2472 miles to Tuktut Nogait National Park in Northern Canada, they stop to rest once for 12 hours in Canada along the way.

Given x as an input of a 24h time in hhmm such as 0130 or 0127, and given that Tuktut Nogait National Park is 7 hours behind BST, write a python script to calculate the time the geese arrive, such that if x is changed it will reflect the correct time of arrival and calculate their total journey time.'''

# Geese Arrival Times

time = 0000

distance_ed_to_ice = 805
distance_ice_to_can = 2472
total_journey_distance = distance_ed_to_ice + distance_ice_to_can
total_journey_time = 89
one_day = 2400
one_hour = 100

arrival_time = time + (total_journey_time * 100) - 700
if arrival_time > 2400:
    arrival_time = arrival_time - one_day
    if arrival_time > 4800:
        arrival_time = arrival_time - (one_day * 2)


print ("The geese will be travelling", total_journey_distance, "miles.")
print ("The Geese will arrive at", arrival_time, ".")
print ("It will take the Geese", total_journey_time, "hours to arrive.")
Reply
#2
I'd approach a bit differently.
Scotland to Iceland - 805miles/50mph = hours travelled.
Add 12 for the layover.
Iceland to Canada = 2472miles/50mph = hours travelled
Add 12 hours for the layover
Now you have the total time.
Take the start time, add the total time, get the ETA. And remember the time zones
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020