当前位置:网站首页>居民用水问题
居民用水问题
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的作用。
边栏推荐
- Object.defineProperty实时监听数据变化并更新页面
- LiveVideoStackCon 2022 Shanghai Station opens tomorrow!
- 多线程涉及的其它知识(死锁(等待唤醒机制),内存可见性问题以及定时器)
- Is DDOS attack really unsolvable?Do not!
- 【七夕如何根据情侣倾听的音乐进行薅羊毛】背景音乐是否会影响情侣对酒的选择
- Opencv——视频跳帧处理
- GCC:头文件和库文件的路径
- The principle of NMS and its code realization
- 4. PCIe 接口时序
- 软件测试技术之最有效的七大性能测试技术
猜你喜欢
缺陷检测(图像处理部分)
创意代码表白
### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionExcep
(17) 51 MCU - AD/DA conversion
How DHCP works
Bit rate vs. resolution, which one is more important?
Gartner Hype Cycle:超融合技术将在2年内到达“生产力成熟期”
The use of pytorch: temperature prediction using neural networks
活动推荐 | 快手StreamLake品牌发布会,8月10日一起见证!
Countdown to 1 day!From August 2nd to 4th, I will talk with you about open source and employment!
随机推荐
手把手基于YOLOv5定制实现FacePose之《YOLO结构解读、YOLO数据格式转换、YOLO过程修改》
内存取证系列1
PCIe Core Configuration
LiveVideoStackCon 2022 Shanghai Station opens tomorrow!
MongoDB construction and basic operations
Knowledge Points for Network Planning Designers' Morning Questions in November 2021 (Part 1)
Exercise: Selecting a Structure (1)
JVM类加载简介
Software Testing Interview Questions: What is Software Testing?The purpose and principle of software testing?
B站7月榜单丨飞瓜数据B站UP主排行榜发布!
A new technical director, who calls DDD a senior, is convinced
跨域解决方案
ora-00604 ora-02429
oracle create user
Getting Started with Kubernetes Networking
Bit rate vs. resolution, which one is more important?
[How to smash wool according to the music the couple listens to during the Qixi Festival] Does the background music affect the couple's choice of wine?
Matlab uses plotting method for data simulation and simulation
安装oracle11的时候为什么会报这个问题
oracle create tablespace