python厘米换算英尺英寸
时间: 2024-01-23 21:15:37 浏览: 30
以下是两种Python厘米换算英尺英寸的例子:
1. 输入厘米数,转化为英尺英寸
```python
cm = input("请输入cm数:")
foot = int(eval(cm) // 30.48) # 1英尺=30.48厘米
inch = 12 * (eval(cm) / 30.48 - foot) # 1英尺=12英寸,将剩余的全部foot转化为inch
print("厘米数{}={}英尺{}英寸".format(cm, foot, inch))
```
2. 输入厘米数,转化为英尺英寸
```python
cm = input("请输入cm数:")
foot = int(eval(cm) // 30.48) # 1英尺=30.48厘米
inch = int(12 * (eval(cm) / 30.48 - foot)) # 将剩余的全部foot转化为inch
print("厘米数{}={}英尺{}英寸".format(cm, foot, inch))
```
相关问题
厘米换算英尺英寸python
要进行厘米到英尺英寸的换算,可以使用以下代码:
```python
def cm_to_feet_inches(cm):
inches = cm / 2.54
feet = inches // 12
remaining_inches = inches % 12
return feet, remaining_inches
cm = 160
feet, inches = cm_to_feet_inches(cm)
print(f"{cm}厘米等于{feet}英尺{inches}英寸")
```
运行结果会显示:160厘米等于5英尺3.0英寸。这意味着160厘米大约等于5英尺3.0英寸。
python英尺厘米换算
以下是Python英尺厘米换算的例子:
1. 厘米转换为英尺和英寸
```python
cm = int(input())
foot = cm/100.0 / 0.3048
inch = (cm/100.0 / 0.3048 - int(foot)) * 12
print(f"{int(foot)} {int(inch)}")
```