Write a function to_secs that converts hours, minutes and seconds to a total number of seconds. Here are some tests that should pass:
test(to_secs(2, 30, 10), 9010)
test(to_secs(2, 0, 0), 7200)
test(to_secs(0, 2, 0), 120)
test(to_secs(0, 0, 42), 42)
test(to_secs(0, -10, 10), -590)
Extend to_secs so that it can cope with real values as inputs. It should always return an integer number of seconds (truncated towards zero):
test(to_secs(2.5, 0, 10.71), 9010)
test(to_secs(2.433,0,0), 8758)
Write three functions that are the "inverses" of to_secs:
1. hours_in returns the whole integer number of hours represented by a total number of seconds.
2. minutes_in returns the whole integer number of left over minutes in a total number of seconds, once the hours have been taken out.
3. seconds_in returns the left over seconds represented by a total number of seconds.
You may assume that the total number of seconds passed to these functions is an integer. Here are some test cases:
test(hours_in(9010), 2)
test(minutes_in(9010), 30)
test(seconds_in(9010), 10)
Which of these tests fail? Explain why.
test(3 % 4, 0)
test(3 % 4, 3)
test(3 / 4, 0)
test(3 // 4, 0)
test(3+4 * 2, 14)
test(4-2+2, 0)
test(len("hello, world!"), 13)
Write a function slope(x1, y1, x2, y2) that returns the slope of the line through the points (x1, y1) and (x2, y2). Be sure your implementation of slope can pass the following tests:
test(slope(5, 3, 4, 2), 1.0)
test(slope(1, 2, 3, 2), 0.0)
test(slope(1, 2, 3, 3), 0.5)
test(slope(2, 4, 1, 2), 2.0)
Then use a call to slope in a new function named intercept(x1, y1, x2, y2) that returns the y-intercept of the line through the points (x1, y1) and (x2, y2)
test(intercept(1, 6, 3, 12), 3.0)
test(intercept(6, 1, 1, 6), 7.0)
test(intercept(4, 6, 12, 8), 5.0)