In: Computer Science
in python
You're always in a hurry and worried about missing your classes.
However, you are afraid to get speed tickets in case you exceed the
speed limit on the road if you leave late from home or work.
Therefore, you need to drive at the maximum speed allowed and make
sure to reach your class on time.
For this purpose, you need to write a program that will read from
the user the maximum speed
limit (assume it is the same across all roads) and the distance to
be traveled (in KM) and then
print the time (in hours and minutes) at which they will have to
leave home or work. You may
also assume that you'll maintain a constant speed till you
arrive.
You may use any built-in function that can help you with
that.
Example:
If the maximum speed limit is 80 km/hr and you're 20 km far from
the university and your class starts at 2:00 pm then you need to
leave your work or home at maximum at 01:45 pm since it takes you
15 minutes to arrive.
thanks for the question, here is the python program.
==================================================================
def main():
# assuming the class starts at 2:00 pm every
day
# tracking the time in military hours and
mins
class_hrs = 14
class_mins = 0
max_speed_limit = int(input('Enter
maximum speed limit (km/hr): '))
distance = int(input('Enter how far is
your university (km): '))
minutes_needed = (distance * 60) //
max_speed_limit
time_to_leave = class_hrs * 60 + class_mins -
minutes_needed
hours = time_to_leave // 60
mins = time_to_leave % 60
if hours>=12:
print('You must
leave at max by {:02d}:{:02d}
p.m'.format(hours-12,mins))
else:
print('You must
leave at max by {:02d}:{:02d}
a.m'.format(hours,mins))
main()
=================================================================