Bonus Practice Problem(When should we leave)

Your mother will take you to the doctor’s clinic for a check-up. She asks the time by which you have to book a taxi. Your mother has some works :  going to the dry-cleaners in the mall, have lunch in the restaurant, buy some dog food at the pet-shop, take money in the bank,  to be done on the way,
It takes 'x' minutes to drive to the mall and park the vehicle, and 'y' minutes to get the clothes dry cleaned, ‘z' minutes for lunch, 'a' minutes to get dog food, 'b' minutes to get money at the bank and 'c' minutes to drive to the doctor’s office from the mall.  Given the values for ‘x’, ‘y’, ‘z’, ‘a’ and ‘b’ and the time of appointment as 'h' hour 'm' minutes, write an algorithm and the subsequent Python code to determine when you should leave home. For example if x is 20, y is 10, z is 45, a is 10, b is 10, c is 20 and h is 14 and m is 0,  then you have to start from home by 12 hour 05 minutes.
Write appropriate functions for accomplishing the task.
Input Format
First line contains the value for ‘x’
Next line contains the value for ‘y’
Next line contains the value for ‘z’
Next line contains the value for ‘a’
Next line contains the value for ‘b’
Next line contains the value for ‘c’
Next line contains the value for ‘h’
Next line contains the value for ‘m’
Output Format
Print the start time from home in ‘hours’ and ‘minutes’ in 24 hour format.  Hours and minutes shall be separated by a space.
Input for the problem
First line contains the value for ‘x’
Next line contains the value for ‘y’
Next line contains the value for ‘z’
Next line contains the value for ‘a’
Next line contains the value for ‘b’
Next line contains the value for ‘c’
Next line contains the value for ‘h’
Next line contains the value for ‘m’
Processing involved 
data = []
for i in range(8):
    data.append(int(input().rstrip()))
hrs = 0
mini = 0
total_min = 0
for i in range(6):
    total_min += data[i]
hrs = total_min//60
mini = total_min%60
hrs = data[-2] - hrs
mini = data[-1] - mini
if mini < 0:
    mini = mini + 60
    hrs -= 1
print(hrs,mini)

Output for the problem
Print the start time from home in ‘hours’ and ‘minutes’ in 24 hour format.  Hours and minutes shall be separated by a space.
Pseudocode
Step1.Get the required data
Step2. Calculate the total time taken to do all the things
Step3. find the total time in hrs and minutes
Step4. Subtract the hrs and min from the appointment time
Step5.End
Program:
data = []
for i in range(8):
    data.append(int(input().rstrip()))
hrs = 0
mini = 0
total_min = 0
for i in range(6):
    total_min += data[i]
hrs = total_min//60
mini = total_min%60
hrs = data[-2] - hrs
mini = data[-1] - mini
if mini < 0:
    mini = mini + 60
    hrs -= 1

print(hrs,mini)

4 comments:

  1. Two numbers are said to be amicable if the sum of proper divisors of one number plus 1, is equal to the other number. All divisors of a number other than 1 and itself, are called proper divisors. For example, the numbers 220 and 284 are amicable as the sum of proper divisors of 220 (i.e.) 1, 2, 4, 5, 10, 11, 20, 22, 44, 55 and 110 is equal to 284 and sum of proper divisors of 284 (i.e.) 1, 2, 4, 71 and 142 is 220. Given two numbers, write an algorithm and the subsequent Python code to Print Yes if the given two numbers are amicable. Print ‘No’ if the given numbers are not amicable. Check for boundary conditions and print 'Invalid input' for wrong input. Write appropriate functions for accomplishing the task.

    Input Format

    First line contains the first number

    Next line contains the second number

    Output Format

    Print either Yes or No

    ReplyDelete
  2. Kangaroo refers to a word carrying another word within it but without transposing any letters. Example: encourage contains courage, cog, cur, urge, core, cure, nag, rag, age, nor, rage and enrage but not run, gen, gone etc. Given two strings, design an algorithm/ flowchart and a Python function to determine if the first string is a Kangaroo word of second.

    Input Format:

    String1

    String2

    Output Format:

    Print True or False

    Boundary Conditions:

    m,n>0

    ReplyDelete
  3. Given a set of elements, write an algorithm and the subsequent ‘C’ program to perform cyclic right shift of the array by 'm' places. For example, if the elements are 12, 13, 16, 7, 10 and m =2 then the resultant set will be 7, 10, 12, 13, 16.



    Input Format

    Number of elements in 'n'

    element1

    element2

    ...

    elementn

    value of 'm'



    Output Format

    Elements in the set after right shift by 'm' places

    ReplyDelete
  4. Error in the code:

    Traceback (most recent call last):
    File "Hello.py", line 3, in
    data.append(int(input().rstrip()))
    EOFError: EOF when reading a line



    please solve asap

    ReplyDelete

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