SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Y Daniel Lang
Chapter:
Functions Strings And Objects
Exercise:
Programming Excercises
Question:1 | ISBN:978013274719 | Edition: 6

Question

(Geometry: area of a pentagon) Write a program that prompts the user to enter the length from the center of a pentagon to a vertex and computes the area of the pentagon, as shown in the following figure.

                                   

The formula for computing the area of a pentagon is Area = 3\sqrt{}3/2 s^2  where s is the length of a side. The side can be computed using the formula s = 2r sin pi/5 where r is the length from the center of a pentagon to a vertex.

Here is a sample run:

Enter the length from the center to a vertex: 5.5
The area of the pentagon is 108.61
 

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

#Importing math module
import math
#Taking the input length from the user
print("Enter the length from the center to a vertex: ")
r = float(input())
#Compute the area of the pentagon
s = (2 * r) * math.sin(math.pi / 5)
area = ((3*math.sqrt(3))/2)*s**2
#Display results
print("The area of the pentagon is {:.2f}".format(area))

Output:

Enter the length from the center to a vertex: 
5.5
The area of the pentagon is 108.61

 

0 0

Discussions

Post the discussion to improve the above solution.