计算圆的周长,面积,代码如下
import math #导入数学模块
radius = int(input('radius(unit: cm): ')) #输入半径
perimeter = 2*math.pi*radius #将直径带入到(C=2πr)
area = math.pi*radius**2 #将半径带入到(S=π*r*r)
# 输出结果
print(f"The perimeter of the circle is:{perimeter}cm")
print(f"The area of the circle is:{area}cm")
若要结果输出为整数,可在变量”perimeter“和area前加int(),代码如下
import math #导入数学模块
radius = int(input('radius(unit: cm): ')) #输入半径
perimeter = 2*math.pi*radius #将直径带入到(C=2πr)
area = math.pi*radius**2 #将半径带入到(S=π*r*r)
# 输出结果
print("The perimeter of the circle is:",int(perimeter),"cm")
print("The area of the circle is:",int(area),"cm")