Python将数字转换为米,厘米和desimeters [英] Python convert numbers into meters, centimeters and desimeters

查看:452
本文介绍了Python将数字转换为米,厘米和desimeters的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如:



1525



15米

2分米器

5厘米



我尝试过:



我完全迷失了,我不知道该怎么办

解决方案

诀窍是使用整合师 [ ^ ]。

我告诉你第一步:

 total_cm =  1525  
m = total_cm // 100
remaining_cm = total_cm - m * 100


Python教程 - Python 3.4.9文档 [ ^ ]你会看到做简单数学是多么容易。

for example:

1525

15 meters
2 decimeters
5 centimeters

What I have tried:

I am just completely lost, I have no idea what to do

解决方案

The trick is using the integer division[^].
I'm showing you the first step:

total_cm = 1525
m = total_cm // 100
remain_cm = total_cm - m * 100


Start with The Python Tutorial — Python 3.4.9 documentation[^] where you will see how easy it is to do simple mathematics.


这篇关于Python将数字转换为米,厘米和desimeters的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆