Skip to content

Latest commit

 

History

History
109 lines (59 loc) · 2.27 KB

File metadata and controls

109 lines (59 loc) · 2.27 KB

Unit 3 Practice

Exercise 1 - Geometry

Let's do a little geometry!

1.1

  • Create three variables a, b and c.

  • Assign a number to each to represent the lengths of the sides of a triangle.

  • Calculate the perimeter of the triangle

    Output

    A triangle with sides of 3, 4, and 5 has a perimeter of 12.
    

1.2

  • Create variables with numbers representing the base and height measurements of the triangle. Select a, b or c to represent the base.

  • Calculate the area of the triangle.

    Output

    A triangle with a base of 5 and a height of 8 has an area of 20.0.
    ---
    
    A triangle with a base of 2.8 and a height of 2.02 has an area of 2.828.
    

1.3

  • Assign a number to a variable to represent the radius of a circle.

  • Use the constant for pi contained within the math module and the radius variable to calculate the circumference and area of a circle.

    Output

    Circle
    
    Radius: 5
    Circumference: 31.4159...
    Area: 78.5398...
    

1.4

  • Calculate the volume of a sphere with the same radius.

    Output

    Sphere
    
    Radius: 5
    Volume: 523.5987...
    

1.5

  • Assign a number to a variable to represent the radius of a second circle.

  • Use the two radii to calculate the area of an annulus.

    Output

    Annulus
    
    Outer Radius: 5
    Inner Radius: 3
    Area: 50.26548245743669
    

Extra challenges

1.6

  • Create two variables, a and b to represent the adjacent sides of a right triangle.

  • Find the hypotenuse of a triangle using a and b. Assign the value to a variable c.

  • Display the result to the user

    A triangle with sides of 65 and 72 has a hypotenuse of 97.
    

1.7

Use the random module to generate random integer values for the circle and sphere's radius and the triangle's base and height.


1.8

Have the user enter all number values used in previous versions. Don't forget that input() always returns a string.

Exercise 1 solution