円柱の体積と表面積を計算するこのプログラムを作成しようとしています。私は現在、そのボリューム部分をコーディングしています。ただし、出力画面では、小数点以下が 2 桁あります。それが示している:
シリンダーの容積は193019.2896193019.2896cm³
なぜ2つあるのですか?
その後、ユーザーが希望する小数点以下の桁数 (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))