0% found this document useful (0 votes)
40 views1 page

Write Code and Test The Code For The Following Functions

The document provides instructions for writing code to calculate the area of triangles using Heron's formula. It includes 5 functions: 1. Area_Triangle(a,b,c) calculates the area given the 3 side lengths, checking that they satisfy the triangle inequality theorem. 2. Area_Triangle1() asks the user to input side lengths, calculates the area, and states if it meets a limit of 125. 3. Area_Triangle2() repeats the process of 2 four times, adding areas to a list. 4. Area_Triangle3() chooses random side lengths from a list. 5. Area_Triangle4() uses a while loop to repeatedly calculate areas from user

Uploaded by

Sachneet Arora
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views1 page

Write Code and Test The Code For The Following Functions

The document provides instructions for writing code to calculate the area of triangles using Heron's formula. It includes 5 functions: 1. Area_Triangle(a,b,c) calculates the area given the 3 side lengths, checking that they satisfy the triangle inequality theorem. 2. Area_Triangle1() asks the user to input side lengths, calculates the area, and states if it meets a limit of 125. 3. Area_Triangle2() repeats the process of 2 four times, adding areas to a list. 4. Area_Triangle3() chooses random side lengths from a list. 5. Area_Triangle4() uses a while loop to repeatedly calculate areas from user

Uploaded by

Sachneet Arora
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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