You are on page 1of 1

CSP Review for Unit 1.

3
Activity 1.3.2 to 1.3.7
Write code and test the code for the following functions:

Given: Heron’s formula for the area of a triangle: 𝐴𝑟𝑒𝑎 = √𝑝(𝑝 − 𝑎)(𝑝 − 𝑏)(𝑝 − 𝑐) where 𝑝 =
(𝑎+𝑏+𝑐)
and 𝑎, 𝑏, 𝑐 𝑎𝑟𝑒 𝑡ℎ𝑒 𝑙𝑒𝑛𝑔𝑡ℎ𝑠 𝑜𝑓 𝑡ℎ𝑒 𝑡ℎ𝑟𝑒𝑒 𝑠𝑖𝑑𝑒𝑠 𝑜𝑓 𝑡ℎ𝑒 𝑡𝑟𝑖𝑎𝑛𝑔𝑙𝑒.
2

1. 𝐴𝑟𝑒𝑎_𝑇𝑟𝑖𝑎𝑛𝑔𝑙𝑒(𝑎, 𝑏, 𝑐) : The function will return the area of a triangle using the three
side lengths of the triangle. The three arguments of the function are the lengths of the
three sides. Use the Triangle Inequality Theorem as a conditional to make sure that the
three lengths will form a triangle. Theorem: The sum of the lengths of any two sides of
a triangle is greater than the length of the third side, 𝑎 + 𝑏 > 𝑐 𝑎𝑛𝑑 𝑎 + 𝑐 > 𝑏 𝑎𝑛𝑑 𝑏 +
𝑐 > 𝑎. The output will be the area of the triangle. (Use assignment 1.3.2 to help.)
o Test both cases of the code.

o
2. 𝐴𝑟𝑒𝑎_𝑇𝑟𝑖𝑎𝑛𝑔𝑙𝑒1(): The function will return the area of a triangle using the three side
lengths of a triangle and state whether or not the area meets a given limit. The user will
be asked to input the values of the lengths of the three sides. Set
variable 𝐴𝑅𝐸𝐴_𝐿𝐼𝑀𝐼𝑇 = 125. The function will state whether or not the area matches
the AREA_LIMIT. If the area does not match the AREA_LIMIT, the function will state
whether or not the value of the area is less than 𝐴𝑅𝐸𝐴_𝐿𝐼𝑀𝐼𝑇, or greater than
AREA_LIMIT. (Use assignment 1.3.3 and 1.3.4 to help.)
3. 𝐴𝑟𝑒𝑎_𝑇𝑟𝑖𝑎𝑛𝑔𝑙𝑒2(): Add to the coding above a 𝐹𝑜𝑟 𝐿𝑜𝑜𝑝 that has the process repeated
4 times and adds the area calculated to a list and the output is the list with the areas.
4. 𝐴𝑟𝑒𝑎_𝑇𝑟𝑖𝑎𝑛𝑔𝑙𝑒3(): Have the side lengths chosen randomly from a list of values.
5. 𝐴𝑟𝑒𝑎_𝑇𝑟𝑖𝑎𝑛𝑔𝑙𝑒4(): Add a while loop and have and has the area calculated until the
value of the area is greater than AREA_LIMIT = 125. Have the user input values to
calculate the area.

You might also like