我試圖使這個程序,其計算的氣缸的體積和表面積;我目前正在編寫卷的一部分。但是,在輸出屏幕中,有兩位小數。它顯示:Python中的兩個小數?
氣缸的容積is193019.2896193019.2896cm³
爲什麼有兩個?
在那之後,我試圖讓程序問多少個小數位(露點)用戶想要的用戶。我怎樣才能做到這一點?
下面是當前的代碼:
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))
一點題外話,把一個值時,'打印內部()'函數,你並不需要顯式調用' str()','print()'函數會自動執行此操作。 (好吧,它得到了對象的'__str__'屬性,這是'str()'調用的)。編輯:只有當不使用fn內的字符串concat。 – gos1
@ gos1:不是在使用'+'先連接值時。 –
這是當我做太多的Java和沒有足夠的Python時所得到的,謝謝! – gos1