Coding for KidsCoding for Kids
Creative LevelsChallengesTeacher's Guide
Vote for features
Advanced Python Development Course
Chapter
>
Level

Math Modules
Math Module Extended

Objective

Calculate the new land extensions to the farm using more functions imported by the math module.

Across the bridge the annex has some offices used to survey the unincorporated land that merges two different parts of the farm. Here we’ll find some land dimensions and measurements, it would be a good idea to sort them and document the data. You can accomplish this by using the math module, in this level we’ll be introduced to a new set of it’s functions we can use to process the data. You use the same import math and math. before functions to use this set:

  • math.radians(): Converts degrees into radians / angles.
  • math.floor(): Rounds number down to a base number.
  • math.ceil(): Rounds number up to a higher number.
  • math.atan2(): Returns the arc tangent between two numbers in radians
  • math.isclose(): Checks if two numbers are close to each other, returns true/false
  • math.fsum(): Adds float point (decimal) numbers together from a list or iterable.
  • math.dist(): Checks the distance between two points, values need to be a lists or iterable.

Start of gathering the raw data from the charts by walking to the light X marks over the red and blue carpet. Use the read() function to identify the raw dimensions needed to take measurements. These measurements are already stored in four variable constants named: red_x , red_y , blue_x and blue_y

Once both sets of data have been identified, walk to the dark X mark over the orange carpet and face the desk. Use the math.radians() and math.ceil() to convert the blue_x and blue_y variables into radians and have them rounded up. Use float() to ensure the constants are decimals that can be edited. For example, for the blue_x variable: convert to radians blue_x = math.radians(float(blue_x)) and round up value blue_x = math.ceil(float(blue_x)) . Do the same for blue_y in this X mark, once done, use the pre-written write() function and add the blue_x and blue_y variables in order to chart them down.

Walk to the dark X mark over the green carpet and use the math.radians() and math.floor() to convert the red_x and red_y variables into radians and have them rounded up. For example, for the red_x variable: convert to radians red_x = math.radians(red_x) and round up value blue_x = math.floor(red_x) . Do the same for red_y in this X mark, once done, use the pre-written write() function and add the red_x and red_y variables in order to chart them down.

Walk to the gold X mark and face the desk, here we will create two new variables, data_a and data_b. Here we will be storing the arc tangents of each set by using math.atan2 function. For data_a we use the blue_x and blue_y variables to populate the function, like this: data_a = math.atan2(blue_x,blue_y) . For data_b , do the same but with red_x and red_y . Once done, use the pre-written write() function and add the data_a and data_b variables in order to chart them down.

Now that the lower desks have been taken care of, walk to the dark X mark over purple carpet, create a variable named comparison and use it with the math.isclose() function, using data_a and data_b as arguments, like this: comparison = math.isclose(data_a, data_b) . Use the pre-written write() function with the comparison variable on this X mark.

Move to the X mark over the white carpet, create a list named data_list and add data_a and data_b in that order. Create a variable named total and use the math.fsum() function with the data_list as an argument, like this: total = math.fsum(data_list) . Use the total variable with the pre-written write() function on this X mark.

Move to the dark X mark over yellow carpet and face the desk, convert data_a and data_b into individual list values, for example for data_a do: data_a = [data_a] . Do the same for data_b in order to convert both variables into iterables for use with the math.dist() function. Create a variable named distance and use it to store the value of math.dist() , use data_a and data_b as arguments for it. Use the distance variable with the pre-written write() function in order to complete the level.

Code book