Elizabeth’s visit
Elizabeth visits
her friend Andrew and then returns home by the same route. She always walks 1
kilometer per hour (km/h) when walking uphill, 4 km/h when walking downhill,
and 2 km/h when walking on level ground. Suppose the path from
Elizabeth's home to Andrew's home consists of 'x' meter in the level ground,
'y' meter in the uphill, 'z' meter in the downhill and Elizabeth starts
from home by 6 a.m. Write an algorithm and the subsequent Python code to
determine when Elizabeth will reach Andrew's home and when she will reach her
home back if she spends 'm1' minutes in Andrew's home. For example, if x is
1000, 'y' is 500, 'z' is 300 and m1 is '30' minutes, then Elizabeth takes
65 min to reach Andrew's home so she will reach Andrew's home by 7 hour
05 min. Elizabeth will take 56 min to walk from Andrew's home to her home
and time when will reach her home back is 8 hour 31 min.
The hour can be
expressed in 12-hour format (not 24-hour format). The minutes elapsed
should be rounded down to the nearest integer.
Input Format
First line contains
the distance ‘x’ in level ground
Next line contains
the distance ‘y’ in uphill
Next line contains
the distance ‘z’ in downhill
Next line contains
the value for ‘ml’ minutes spent at Andrew’s home
Output Format
Print time by which
Elizabeth will reach Andrew’s home. Print hours and minutes separated by a
space
Print time by which Elizabeth will
reach back her home. Print hours and minutes separated by a space
Input:
uphill,dowhill,level
ground distances and time taken at andrew's house
Processing:
from
math import ceil
x
= int(input())
y
= int(input())
z
= int(input())
ml
= int(input())
def
time_taken(level,up,down):
time = ceil(level*60/2000 + up*60/1000 +
down*60/4000)
return time
def
time_clock(time_consumed):
hrs = 6 + time_consumed//60
minute = 0 + time_consumed%60
if len(str(minute)) == 1:
minute = '0' + str(minute)
return hrs,minute
time_andrew
= time_taken(x,y,z)
time_home = time_taken(x,z,y) + ml + time_andrew
Output:
Display
the time when elizabeth meets Andrew and time when she returns home
Proof:
Proof:
Program:
from
math import ceil
x
= int(input())
y
= int(input())
z
= int(input())
ml
= int(input())
def
time_taken(level,up,down):
time = ceil(level*60/2000 + up*60/1000 +
down*60/4000)
return time
def
time_clock(time_consumed):
hrs = 6 + time_consumed//60
minute = 0 + time_consumed%60
if len(str(minute)) == 1:
minute = '0' + str(minute)
return hrs,minute
time_andrew
= time_taken(x,y,z)
time_home
= time_taken(x,z,y) + ml + time_andrew
print(time_clock(time_andrew)[0],time_clock(time_andrew)[1],sep
= ' ')
print(time_clock(time_home)[0],time_clock(time_home)[1],sep
= ' ')
Algorithm:
Step1.
Get x,y,z and ml
Step2.
Define the time taken function with three parameters level, up, down
Step2.1
assign time as the sum of level multiplied by 0.03 up multiplied by 0.06 and
down multiplied by 60/4000
Step2.2
return time
Step3.
Define time_clock function with one parameter time_consumed
Step3.1
assign hrs as the sum of 6 and the value obtained after dividing time_consumed
by 60
Step3.2
assign minute as the sum of 0 and the value obtained which is the remainder
when time_consumed is divided by 60
Step3.3
return hrs,minute
Step4.
Call the time_taken function twice to calculate the time when she reached
andrew’s home and when she returned home
Step5.
Call the time_clock function twice get the time in the correct format and
display the time
Step6.
End
No comments:
Post a Comment