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
icon
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
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
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
steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
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%
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
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Processes of 3D Graphics
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
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)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education