Python Homework #1

Instructions:

You will be creating several functions (all in the same file). Be sure to include, after each function, the appropriate test cases that you've devised. There must be at least 2 test cases for each function, in the following format: print("fred(18) should be 34, and is: ", fred(18)) After using the test lines, you may comment them out.
  1. Create the function is_leap(year) which will be given a positive integer. The function will return True if the year in question is a leap year. Be sure to include test cases to validate your function.

  2. Create the function sum_squares(low,high) which will be given two integers, with the requirement that low <= high. The function will add up all of the squares of the numbers between (and including) low and high and return tthat value. Be sure to include test cases to validate your function.

  3. Create the function sum_powers(low,high,power) which will be given two integers and a power (which is a number that is not necessarily an integer or even a positive number), with the requirement that low <= high. The function will add up all of the powers of the numbers between (and including) low and high and return that value. For instance, of power is 2, then it's the sum of squares. If it's 3 then the sum of cubes, etc.

  4. Create the function lcm(a,b) which will be given two positive integers. The function should return the least common multiple of a and b (i.e. the smallest integer that is divisible by both a and b). e.g: lcm(12, 8) -> 24.

Challenge problem (optional):

Create the function dec_to_bin(n), which will be given a positive integer, and should return a string representing the same value in binary
Examples:
dec_to_bin(0)  -> "0"
dec_to_bin(1)  -> "1"
dec_to_bin(5)  -> "101"
dec_to_bin(13) -> "1101"
# We haven't covered strings yet, but you can put together a string like so:
    s = ""
    s = "1" + s