First, compare the areas of the two polygons. Print out which polygon's area is greater (or if they are equal). Then print out the area values (polygon 1's first then polygon 2's). The output should be formatted as follows:
First, compare the areas of the two polygons. Print out which polygon's area is greater (or if they are equal). Then print out the area values (polygon 1's first then polygon 2's). The output should be formatted as follows:
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
Can you solve it in Python? Thanks.
![If one of your polygons is a hexagon, compute the area based on its side length. The
following equation may be useful, where a is the side length and A is the area of the
hexagon:
A =
=
Or
3₁/3
2
Part 4 (Computing the perimeters)
Compute the perimeters of both polygons by just multiplying the number of sides of the polygon
by the side length. Triangles have 3 sides, squares have 4 sides, and hexagons have 6 sides.
a²
Part 5 (Comparing the values)
First, compare the areas of the two polygons. Print out which polygon's area is greater (or if they
are equal). Then print out the area values (polygon 1's first then polygon 2's). The output should
be formatted as follows:
Polygon 1's area is larger
53.42 34.22
Or
The areas are equal
100.0 100.0
Second, compare the perimeters of the two polygons. Print out which polygon's perimeter is
greater (or if they are equal). Then print out the perimeter values (polygon 1's first then polygon
2's). The output should be formatted as follows:
Polygon 2's perimeter is larger
12.0 16.0
The perimeters are equal
40.0 40.0](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F2bdda45c-647a-4dc4-b729-607d761f96c7%2F336d41b5-43f2-41aa-8c0e-65ee5846cd42%2Flgp0j4i_processed.jpeg&w=3840&q=75)
Transcribed Image Text:If one of your polygons is a hexagon, compute the area based on its side length. The
following equation may be useful, where a is the side length and A is the area of the
hexagon:
A =
=
Or
3₁/3
2
Part 4 (Computing the perimeters)
Compute the perimeters of both polygons by just multiplying the number of sides of the polygon
by the side length. Triangles have 3 sides, squares have 4 sides, and hexagons have 6 sides.
a²
Part 5 (Comparing the values)
First, compare the areas of the two polygons. Print out which polygon's area is greater (or if they
are equal). Then print out the area values (polygon 1's first then polygon 2's). The output should
be formatted as follows:
Polygon 1's area is larger
53.42 34.22
Or
The areas are equal
100.0 100.0
Second, compare the perimeters of the two polygons. Print out which polygon's perimeter is
greater (or if they are equal). Then print out the perimeter values (polygon 1's first then polygon
2's). The output should be formatted as follows:
Polygon 2's perimeter is larger
12.0 16.0
The perimeters are equal
40.0 40.0
![Project 2 - Comparing Polygons
The goal of this activity is to create a program that will compare the area and perimeters
of two regular polygons. A polygon is regular when all angles are equal and all sides are equal.
This program will support triangles, squares, and hexagons.
Part 1 - Create a header comment with the title of this program, your name, and the date.
Part 2 (Taking in user input)
Part 2 - Ask the user for the shape (triangle, square, or hexagon) and side length of both
polygons. You can assume that the user's input for the shape will be valid (either triangle, square,
or hexagon) and in lowercase. You can assume that the user's input for the side length will be a
positive number (could be a decimal). Once you run your program, the prompts for the user
should be formatted as follows (must match this exactly):
What is your first shape? triangle
What is the length of its side? 2
What is your second shape? square
What is the length of its side? 1.4
Part 3 (Computing the areas)
3.1 Triangle
If one of your polygons is a triangle, compute the area based on its side length. The
following equation may be useful, where a is the side length and A is the area of the
triangle:
A =
3
3.2 Square
If one of your polygons is a square, compute the area based on its side length. The
following equation may be useful, where a is the side length and A is the area of the
square:
2
A =
a²
3.3 Hexagon](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F2bdda45c-647a-4dc4-b729-607d761f96c7%2F336d41b5-43f2-41aa-8c0e-65ee5846cd42%2Fuqd1u2_processed.jpeg&w=3840&q=75)
Transcribed Image Text:Project 2 - Comparing Polygons
The goal of this activity is to create a program that will compare the area and perimeters
of two regular polygons. A polygon is regular when all angles are equal and all sides are equal.
This program will support triangles, squares, and hexagons.
Part 1 - Create a header comment with the title of this program, your name, and the date.
Part 2 (Taking in user input)
Part 2 - Ask the user for the shape (triangle, square, or hexagon) and side length of both
polygons. You can assume that the user's input for the shape will be valid (either triangle, square,
or hexagon) and in lowercase. You can assume that the user's input for the side length will be a
positive number (could be a decimal). Once you run your program, the prompts for the user
should be formatted as follows (must match this exactly):
What is your first shape? triangle
What is the length of its side? 2
What is your second shape? square
What is the length of its side? 1.4
Part 3 (Computing the areas)
3.1 Triangle
If one of your polygons is a triangle, compute the area based on its side length. The
following equation may be useful, where a is the side length and A is the area of the
triangle:
A =
3
3.2 Square
If one of your polygons is a square, compute the area based on its side length. The
following equation may be useful, where a is the side length and A is the area of the
square:
2
A =
a²
3.3 Hexagon
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps with 2 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question
Why there is syntax error in line 23?
![Spyder
File Edit Search Source Run Debug Consoles Projects Tools View Help
8
I II▶
1
2
3
C:\Users\junji\OneDrive\Desktop\miscellaneous\Project2_Ying1.py
4
5
6
7
8
9
#497898
16
17
14 # Find Area and Perimeter of First Shape
19
10
import math
11 First_Shape=input("What is your first shape? ")
12 First_length=float(input("What is the length of its side? "))
13
20
21
22
23
15 if(First_Shape=="triangle"):
1.
28
29
30
31
₁
Project2_Zhang.py X Project3_Zhang.py X Project2_Ying.py X
# -*- coding: utf-8 -*-
|| || ||
32
33
34
35
Created on Sun Sep 25 18:16:47 2022
@author: junji
|| || ||
36
37
38
18 elif (First_Shape=="square"):
39
40
# Compare Area and Perimeter, Name=ABC,Date=26 September 2022
First_Area=(math.sqrt(3)/4)*First_length*First_length
First Perimeter-First_length*3
First_Area-First_length*First_length
First Perimeter-First_length*4
elif (First_Shape=="hexagon"):
24
25 Second_Shape=input("What is your first shape? ")
26 Second_length=float(input("What is the length of its side? "))
27
First Perimeter-First_length*6
First_Area=(((3*math.sqrt(3))/2)*First_length*First_length
Second_Perimeter=3*Second_length
Project2_Ying1.py X
# Find Area and Perimeter of Second Shape
if (Second_Shape=="triangle"):
Second_Area=(math.sqrt(3)/4)*Second_length*Second_length
elif (Second_Shape=="square"):
Second_Area=Second_length*Second_length
Second_Perimeter=4*Second_length
↑
elif (Second_Shape=="hexagon"):
Second_Perimeter=6*Second_length
61°F
Rain coming
# Compare Area
if(First_Area>Second_Area):
Second_Area=(((3*math.sqrt(3))/2)*Second_length*Second_length
▶▶
r
■ E
■
C:\Users\junji\OneDrive\Desktop\miscellaneous
Source Editor
num1
L
Object
Definition : num1 ([x]) -> integer int (x, base 10) -> integer
Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.____int__(). For floating point
numbers, this truncates towards zero.
If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given
base. The literal can be preceded by '+' or '-' and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36.
Base 0 means to interpret the base from the string as an integer literal. >>> int('0b100', base=0) 4
Console 1/A X
junji/OneDrive/Desktop/miscellaneous')
File "<unknown>", line 23
First Perimeter=6*First_length
^
In [34]: runfile('C:/Users/junji/OneDrive/Desktop/miscellaneous/Project2_Yingl.py', wdir='C:/Users/
SyntaxError: invalid syntax
junji/OneDrive/Desktop/miscellaneous')
File "<unknown>", line 23
First Perimeter-First_length*6
^
T
In [35]: runfile('C:/Users/junji/OneDrive/Desktop/miscellaneous/Project2_Yingl.py', wdir='C:/Users/
SyntaxError: invalid syntax
O
Help Variable Explorer Plots Files
O
X
6:20 PM
9/25/2022
=
IPython Console History
internal (Python 3.8.10) Completions: internal ✓ LSP: Python Line 23, Col 35 UTF-8 CRLF RW Mem 51%](https://content.bartleby.com/qna-images/question/2bdda45c-647a-4dc4-b729-607d761f96c7/8536f1ae-9eb5-4f18-80b3-371f270c8f75/xvj81a_thumbnail.jpeg)
Transcribed Image Text:Spyder
File Edit Search Source Run Debug Consoles Projects Tools View Help
8
I II▶
1
2
3
C:\Users\junji\OneDrive\Desktop\miscellaneous\Project2_Ying1.py
4
5
6
7
8
9
#497898
16
17
14 # Find Area and Perimeter of First Shape
19
10
import math
11 First_Shape=input("What is your first shape? ")
12 First_length=float(input("What is the length of its side? "))
13
20
21
22
23
15 if(First_Shape=="triangle"):
1.
28
29
30
31
₁
Project2_Zhang.py X Project3_Zhang.py X Project2_Ying.py X
# -*- coding: utf-8 -*-
|| || ||
32
33
34
35
Created on Sun Sep 25 18:16:47 2022
@author: junji
|| || ||
36
37
38
18 elif (First_Shape=="square"):
39
40
# Compare Area and Perimeter, Name=ABC,Date=26 September 2022
First_Area=(math.sqrt(3)/4)*First_length*First_length
First Perimeter-First_length*3
First_Area-First_length*First_length
First Perimeter-First_length*4
elif (First_Shape=="hexagon"):
24
25 Second_Shape=input("What is your first shape? ")
26 Second_length=float(input("What is the length of its side? "))
27
First Perimeter-First_length*6
First_Area=(((3*math.sqrt(3))/2)*First_length*First_length
Second_Perimeter=3*Second_length
Project2_Ying1.py X
# Find Area and Perimeter of Second Shape
if (Second_Shape=="triangle"):
Second_Area=(math.sqrt(3)/4)*Second_length*Second_length
elif (Second_Shape=="square"):
Second_Area=Second_length*Second_length
Second_Perimeter=4*Second_length
↑
elif (Second_Shape=="hexagon"):
Second_Perimeter=6*Second_length
61°F
Rain coming
# Compare Area
if(First_Area>Second_Area):
Second_Area=(((3*math.sqrt(3))/2)*Second_length*Second_length
▶▶
r
■ E
■
C:\Users\junji\OneDrive\Desktop\miscellaneous
Source Editor
num1
L
Object
Definition : num1 ([x]) -> integer int (x, base 10) -> integer
Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.____int__(). For floating point
numbers, this truncates towards zero.
If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given
base. The literal can be preceded by '+' or '-' and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36.
Base 0 means to interpret the base from the string as an integer literal. >>> int('0b100', base=0) 4
Console 1/A X
junji/OneDrive/Desktop/miscellaneous')
File "<unknown>", line 23
First Perimeter=6*First_length
^
In [34]: runfile('C:/Users/junji/OneDrive/Desktop/miscellaneous/Project2_Yingl.py', wdir='C:/Users/
SyntaxError: invalid syntax
junji/OneDrive/Desktop/miscellaneous')
File "<unknown>", line 23
First Perimeter-First_length*6
^
T
In [35]: runfile('C:/Users/junji/OneDrive/Desktop/miscellaneous/Project2_Yingl.py', wdir='C:/Users/
SyntaxError: invalid syntax
O
Help Variable Explorer Plots Files
O
X
6:20 PM
9/25/2022
=
IPython Console History
internal (Python 3.8.10) Completions: internal ✓ LSP: Python Line 23, Col 35 UTF-8 CRLF RW Mem 51%
Solution
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education