Problem Set 6(Elizabeth Walk)

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, 6 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 ‘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 38 min to reach Andrew’s home so she will reach Andrew’s home by 6 hour 38 min. Elizabeth will take 34 min to walk from Andrew’s home to her home and time when will reach her home back is 7 hour 42 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
PROOF:
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 + up*60/2000 + down*60/6000)
    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

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 + up*60/2000 + down*60/6000)
    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.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

3 comments:

  1. the output is not matching for the first test condition can u please see to it
    Expected Output:
    6 40
    7 47
    Your Program Output:
    6 43
    7 42

    ReplyDelete
    Replies
    1. Please provide the input for the test condition...only then can i check and help you because there are three different question on elizabeth's the first one is walk ,then we have an exercise and we also have a visit question..check which one is yours and also provide the input please

      Delete
    2. 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

      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...