我正在尝试制作这个计算圆柱体的体积和表面积的程序;我目前正在编码它的音量部分。但是,在输出屏幕中,有两位小数。表明:
圆柱体体积为193019.2896193019.2896cm³
为什么有两个?
之后,我试图让程序询问用户用户想要多少小数位 (dp)。我怎样才能做到这一点?
这是当前代码:
print("Welcome to the volume and surface area cylinder calculator powered by Python!")
response = input("To calculate the volume type in 'vol', to calculate the surface area, type in 'SA': ")
if response=="vol" or response =="SA":
pass
else:
print("Please enter a correct statement.")
response = input("To calculate the volume type in 'vol', to calculate the surface area, type in 'SA': ")
if response=="vol":
#Below splits
radius, height = [float(part) for part in input("What is the radius and height of the cylinder? (e.g. 32, 15): ").split(',')]
PI = 3.14159 #Making the constant PI
volume = PI*radius*radius*height
print("The volume of the cylinder is" + str(volume) + "{}cm\u00b3".format(volume))