Courses‎ > ‎Intro to CS - Full Year‎ > ‎Spring‎ > ‎Dyrland-Weaver‎ > ‎Work‎ > ‎

Work 16: 3/15

posted Mar 15, 2019, 11:33 AM by JonAlf Dyrland-Weaver   [ updated Mar 15, 2019, 11:54 AM ]
Write the following python functions in a single .py file.
  • closer_number
    • Takes 3 numbers as arguments.
    • Returns a string that states which of the first two arguments is closer to the third.
    • By closeness we are referring to the distance between 2 numbers on a number line.
      • The distance between 16 and 10 is 6
      • The distance between 7 and 10 is 3
      • 7 is closer to 10 than 16
    • Examples
      • closer_number(7, 16, 10) ==> '7 is closer to 10'
      • closer_number(20, 3, 8) ==> '3 is closer to 8'
      • closer_number (-5, 8, 0) ==> '-5 is closer to 0'
  • num_table
    • Takes 2 positive integer parameters (a, b)
    • Creates and returns a string containing the code for an HTML table with the following information for every integer (n) from a to b:
      • n, n^2, square root of n.
      • Each value should be it's own cell in the table.
      • Each new value of n should be a new row.
      • The table should look something like this:


    • Check that your function is creating valid HTML by copying the output and pasting it into a plain text file and viewing it in a web browser.
      • Remember, html attributes need to be surrounded by "s, so create your python strings accordingly.
submit this as strings_1
Comments