In this lab, you will use user input and conditional statements to identify shapes based on the number of sides and some other properties as given by the user.
-
Write a program that asks the user to think of a shape and input how many sides it has. Then, if the user is thinking of a triangle, tell him or her so. Regardless of whether or not the shape was a triangle, thank the user for playing.
-
Modify your program to give an appropriate message both when the user is thinking of a triangle and when he or she is not thinking of a triangle. Give the same thank you message afterward in either case.
You will now expand your program from above so that instead of just deciding if a shape is a triangle or not, your script will be able to name the specific polygon. Your script must be able to identify at least the following shapes:
Number of sides | Polygon name |
---|---|
3 | Triangle |
4 | Quadrilateral |
5 | Pentagon |
6 | Hexagon |
any other number | Unknown |
-
Fill out a planning worksheet for the above script. Make sure you consider all aspects of the program carefully.
-
Write the program. Be sure that your program works correctly in all cases.
Quadrilaterals come in many different varieties. Add scripting to your script so that, if the user is thinking of is a quadrilateral, you ask more questions to find out which type of quadrilateral it is. Your script should give the most specific name that applies. The following table describes the quadrilaterals you should know about from most to least specific:
Property | Quadrilateral name |
---|---|
All four sides have the same length and all four angles have the same measure. | Square |
Not a square and all four angles have the same measure. | Rectangle |
Not a rectangle and each side is parallel to one other side. | Parallelogram |
Not a parallelogram and two sides are parallel to each other. | Trapezoid |
Not a trapezoid | Unknown quadrilateral |
-
Fill out a planning worksheet for the above script. Make sure you consider all aspects of the program carefully.
-
Write the program. Be sure that your program works correctly in all cases.
-
Save your project as Lab2.3.
Criteria | Points |
---|---|
1 Identifies triangle | 0.5 |
2 Identifies polygons | 1.0 |
3 Identifies quadrilaterals | 0.5 |
Totals | 2.0 |