打印方程的结果

时间:2018-03-21 17:00:04

标签: printing formulas

from math import tan,pi

def polygon_area(sides, length):
     """Returns the area of a regular polygon."""
        sides= 5
        length = 7 
        return (sides *(length **2) /(4 * (tan(pi)/sides)
print ("The area of the polygon is," % polygon_area)

我在做或不做一些非常有用的补救措施。我的程序崩溃了print语句。任何想法/指导/推动赞赏

1 个答案:

答案 0 :(得分:0)

我在这里看到了不同的问题。





首先,你不要在返回线上正确地关闭括号。


&#xA ;

其次,print语句没有正确调用函数。你需要传递两个参数。





最后(可选的修复),在你的函数中你硬编码边和长度覆盖参数。


& #xA;

解决方案#1修复问题#1和#2:




 来自math import tan,pi

 def polygon_area (边长):
双方= 5
长度= 7
 return(sides *(length ** 2)/(4 *(tan(pi)/ sides)))
 print(“多边形的区域是”,“polygon_area(5,7))&#xA ;  




解决所有问题的解决方案#2




 来自math import tan ,pi

 def polygon_area(边,长度):
 return(sides *(length ** 2)/(4 *(tan(pi)/ sides)))
 print(“多边形的区域是”,“polygon_area(5,7))&#xA ;