Problem 7

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)

Problem 8

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)

Problem 9

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)

Problem 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)

Problem 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)
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.