Practice Problem 6-Elizabeth's Trip

Practice Problem 6-Elizabeth's Trip

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 4 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 30 min to reach Andrew's home so she will reach Andrew's home by 6 hour 30 min. Elizabeth will take 26 min to walk from Andrew's home to her home and time when will reach her home back is 7 hour 26 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 plain
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

PROGRAM:

x=float(input())
y=float(input())
z=float(input())
ml=float(input())
hr=6
def round2(n):
    if(n-round(n)>=0.5):
        return(round(n)+1)
    else:
        return(round(n))
tmin=round2(x/4*(18/(5*60)))+round2(y/2*(18/(5*60)))+round2(z/6*(18/(5*60)))
if(tmin<60):
    print(hr,' ',tmin)
else:
    hr=hr+tmin//60
    tmin=tmin%60
    print(hr,' ',tmin)
tmin2=tmin+ml+round2(x/4*(18/(5*60)))+round2(y/6*(18/(5*60)))+round2(z/2*(18/(5*60)))
if(tmin2<60):
    print(hr,' ',tmin2)
else:
    hr=int(hr+tmin2//60)
    tmin2=int(tmin2%60)
    print(hr,' ',tmin2)

PROCESSING:

def round2(n):
 if(n-round(n)>=0.5):
  return(round(n)+1)
 else:
  return(round(n))
tmin=round2(x/4*(18/(5*60)))+round2(y/2*(18/(5*60)))+round2(z/6*(18/(5*60)))
if(tmin<60):
 print(hr,’ ‘,tmin)
else:
 hr=hr+tmin//60
 tmin=tmin%60
 print(hr,’ ‘,tmin)
tmin2=tmin+ml+round2(x/4*(18/(5*60)))+round2(y/6*(18/(5*60)))+round2(z/2*(18/(5*60)))
if(tmin2<60):
 print(hr,’ ‘,tmin2)
else:
 hr=int(hr+tmin2//60)
 tmin2=int(tmin2%60)
 print(hr,’ ‘,tmin2)

PSEUDOCODE:

1.START
2.READ x,y,z,ml
3.SET hr=6
4.DEFINE function round2(n):
 4.i)IF n-round(n)>=0.5:
  4)i)a) RETURN round(n) +1
 4).ii ELSE:
  4)ii)b) RETURN round(n)
5.COMPUTE tmin=round2(x/4*(18/(5*60)))+round2(y/2*(18/(5*60)))+round2(z/6*(18/(5*60)))
6.IF (tmin<60):
 6.i) DISPLAY hr , tmin
7)ELSE:
 7)i COMPUTE hr=hr+tmin//60
 7)ii COMPUTE tmin=tmin%60
 7)iii DISPLAY hr,min
8. COMPUTE tmin2 =tmin+ml+round2(x/4*(18/(5*60)))+round2(y/6*(18/(5*60)))+round2(z/2*(18/(5*60)))
9.IF(tmin2<60):
 9)i DISPLAY(hr,’ ‘,tmin2)
10.ELSE:
 10)i COMPUTEhr=int(hr+tmin2//60)
 10)ii COMPUTE tmin2=int(tmin2%60)
 10)iii DISPLAY (hr,’ ‘,tmin2)
11.END

Comments

Popular posts from this blog

MATLAB WEEK-2

PRACTICE PROBLEM 8

Practice Problem 6-Isomorphic Numbers