Problem Set 6(Elizabeth's morning walk(Id-3100))

Elizabeth's morning walk(Id-3100)
Elizabeth visits her friend Andrew and then returns home by the same route. She always walks 2 kilometers per hour (km/h) when walking uphill, 4 km/h when walking downhill, and 3 km/h when walking on level ground. Suppose the path from Elizabeth's home to Andrew's home consists of 'y' meter in the level ground, 'x' 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 y is 1000, 'x’ is 500, 'z' is 300 and m1 is '30' minutes, then Elizabeth takes 40 min to reach Andrew's home so she will reach Andrew's home by 6 hour 40 min. Elizabeth will take 37 min to walk from Andrew's home to her home and time when will reach her home back is 7 hour 47 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 uphill

Next line contains the distance ‘y’ in plain

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/3000) + ceil(up*60/2000) + ceil(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(y,x,z)
time_home = time_taken(y,z,x) + ml + time_andrew

Output:
Display the time when elizabeth meets Andrew and time when she returns home
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/3000) + ceil(up*60/2000) + ceil(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(y,x,z)
time_home = time_taken(y,z,x) + 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.02, up multiplied by 0.03 and down multiplied by 0.01
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

2 comments:

  1. I'm getting the wrong output. Instead of 6 40 and 7 47, I am getting 6 45 and 7 49. Could you please check that.

    ReplyDelete
    Replies
    1. check the screenshot....i got the correct answer

      Delete

Bonus Practice Problems(GMT To IST)

IST (Indian Standard Time) is 5 hours 30 minutes ahead of GMT(Greenwich Mean Time). Develop an algorithm and write the Python code to find...