Polygon area | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Polygon area

formula of polygon area if all side of polygon is equal: (n * s ^ 2) / 4 * tan(π / n) where n is number of side of polygon and s is side's length can someone correct my code please import math sides = int(input("number of side >> ")) sides_l = int(input("side length >> ")) a = math.pi / sides p_area = sides * sides_l ** 2 / 4 * math.tan(a) print(f"number of side: {sides} side length: {sides_l} area of polygon: {round(p_area, 3)}") first input: 6 second input: 5 #expect output 64.952 #my output 21.637 why my answer is not match with expect answer ?

13th Dec 2021, 2:07 PM
キャサリン
キャサリン - avatar
2 Answers
+ 6
キャサリン , use the formula this way: ... p_area = sides * (sides_l ** 2) / (4 * math.tan(a)) ...
13th Dec 2021, 3:38 PM
Lothar
Lothar - avatar
+ 1
Lothar sorry. i didn't notice that there is a parenthesis cover all last part of formula thank you! you save my day!
13th Dec 2021, 3:58 PM
キャサリン
キャサリン - avatar