当前位置:网站首页>居民用水问题
居民用水问题
2022-08-05 01:09:00 【算法与编程之美】
0 引言
在学习python的过程中,我们都只是简单的学习到了知识点,并没有应用在实际问题中,而通过本次的博客,将直接把python应用于现实生活中的问题,这样便将我们的python灵活应用了,使我们学到的python能真正活学活用。
1 问题
相信每个人的家里都有水表,并且需要通过用水的量来决定价格。在python中,我们同样可以如此来应用于判断决定水的费用,这样便足够简单并且能将所学应用于生活中,大大减轻我们的运算。
2 方法
首先要应用一种输入格式,让用户能自己输入自己的用水量,再应用判断将水费的计算方式列出,在各自的范围内计算即可,最后再输出该用户的用水量所对应的费用即可,然后注意输出格式,保留小数后两位即可。
3 实验结果与讨论
最后通过实验证明,该方法执行有效:
代码清单 1
| x=int(input()) if x<=15: y=4/3*x else: y=2.5*x-17.5 print('%.2f'%(y)) |
4 结语
最后,我们就将我们现实生活中的用水问题直接用python解决了,而且解决方法很简单,就是一个判断加上数学计算。所以学好python后,我们一定要活学活用,发挥出python的作用。
边栏推荐
- 跨域解决方案
- PCIe 核配置
- GCC:头文件和库文件的路径
- 2022 Multi-school Second Session K Question Link with Bracket Sequence I
- Lattice PCIe 学习 1
- Zombie and orphan processes
- Software testing interview questions: Please draw the seven-layer network structure diagram of OSI and the four-layer structure diagram of TCP/IP?
- Helm Chart
- 详细全面的postman接口测试实战教程
- After the staged testing is complete, have you performed defect analysis?
猜你喜欢

CNI (Container Network Plugin)

Exercise: Selecting a Structure (1)

Use of pytorch: Convolutional Neural Network Module

A new technical director, who calls DDD a senior, is convinced

详细全面的postman接口测试实战教程

Activity Recommendation | Kuaishou StreamLake Brand Launch Conference, witness together on August 10!

如何发现一个有价值的 GameFi?

Are testing jobs so hard to find?I am 32 this year and I have been unemployed for 2 months. What should an older test engineer do next to support his family?

B站7月榜单丨飞瓜数据B站UP主排行榜发布!

sqlite--nested exception is org.apache.ibatis.exceptions.PersistenceException:
随机推荐
GCC: paths to header and library files
Pytorch使用和技巧
Interview summary: Why do interviewers in large factories always ask about the underlying principles of Framework?
10年测试经验,在35岁的生理年龄面前,一文不值
FSAWS 的全球基础设施和网络
Gartner Hype Cycle:超融合技术将在2年内到达“生产力成熟期”
JVM类加载简介
DHCP的工作过程
XMjs跨域问题解决
If capturable=False, state_steps should not be CUDA tensors
PCIe 核配置
Software testing interview questions: What are the three modules of LoadRunner?
配置类总结
linux(centOs7)部署mysql(8.0.20)数据库
C# const readonly static 关键字区别
新来个技术总监,把DDD落地的那叫一个高级,服气
Why is this problem reported when installing oracle11
torch.autograd.grad求二阶导数
If capturable=False, state_steps should not be CUDA tensors
Method Overriding and Object Class