Friday, February 1, 2019

Units of Time

  • Problem Description

    Create a program that reads a duration from the user as a number of days, hours, minutes, and seconds. Compute and display the total number of seconds represented by this duration
  • CODING ARENA
  • SECONDS_PER_MINUTE  = 60
    SECONDS_PER_HOUR    = 3600
    SECONDS_PER_DAY     = 86400
    days    = int(input())
    hours   = int(input())
    minutes = int(input())
    seconds = int(input())
    print("Days=",days)
    print("Hours=",hours)
    print("Minutes=",minutes)
    print("Seconds=",seconds)
    total_seconds = days * SECONDS_PER_DAY
    total_seconds = total_seconds + ( hours * SECONDS_PER_HOUR)
    total_seconds = total_seconds + ( minutes * SECONDS_PER_MINUTE)
    total_seconds = total_seconds + seconds
     
    print("Total=","%d"%(total_seconds))
  • Test Case 1

    Input (stdin)
    6
    
    12
    
    34
    
    45
    
    
    Expected Output
    Days= 6
    
    Hours= 12
    
    Minutes= 34
    
    Seconds= 45
    
    Total= 563685
  • Test Case 2

    Input (stdin)
    9
    
    20
    
    23
    
    25
    
    
    Expected Output
    Days= 9
    
    Hours= 20
    
    Minutes= 23
    
    Seconds= 25
    
    Total= 851005

No comments:

Post a Comment