Python 程式讀取身高(釐米)並將其轉換為英尺和英寸
當需要讀取以“釐米 (cm)”為單位的身高並將其轉換為“英尺”和“英寸”時,可以使用“round”方法。
以下是演示示例 −
示例
in_cm=int(input("Enter the height in centimeters..."))
in_inches=0.394*in_cm
in_feet=0.0328*in_cm
print("The length in inches is ")
print(round(in_inches,2))
print("The length in feet is")
print(round(in_feet,2))輸出
Enter the height in centimeters...178 The length in inches is 70.13 The length in feet is 5.84
說明
使用者輸入為“釐米 (cm)”。
將其乘以 0.394,可以轉換成英寸。
將其賦值給變數。
將其乘以 0.0328,可以轉換成英尺。
將其賦值給變數。
將其四捨五入到最近的兩位小數。
這兩種轉換值都在控制檯上以輸出的形式顯示。
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP