Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Initializing the file and beginning the operation
- inFile = open("marshoot.txt","r")
- # Get the number of test cases
- testCases = inFile.readline()
- testCases = testCases[3:6]
- # read first line
- line = inFile.readline()
- #turn test cases into and integer
- testCases = int(testCases)
- #Establish our test case number
- testCaseNum = 1
- # Function to do math and compile math results
- def time_formatter(seconds):
- #calculates the time for all units
- sec = int(round(seconds, 0))
- min = sec // 60
- sec = sec % 60
- hr = min // 60
- min = min % 60
- day = hr // 24
- hr = hr % 24
- #turns values into printable statements
- sec = str(sec)
- min = str(min)
- hr = str(hr)
- day = str(day)
- #display results
- global testCaseNum
- print("Test case number " + str(testCaseNum) + ":")
- print(day + " days " + hr + " hours " + min + " minutes " + sec + " seconds ")
- testCaseNum = testCaseNum + 1
- #define the loop to tead every line
- for x in range(testCases):
- #split the lines up by spaces
- values = line.split(" ")
- #get the distance and make it an integer
- distance = values[0]
- distance = float(distance)
- distance = distance * 1000000
- #get the speed and make it an integer
- speed = values[1]
- speed = float(speed)
- #Calculate the time it takes
- time = ((distance / speed) * 3600)
- #call the function to calculate time
- time_formatter(time)
- #read next line
- line = inFile.readline()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement