当前位置:网站首页>计算水费问题
计算水费问题
2022-06-22 07:58:00 【算法与编程之美】
0 引言
在生活中,水是人们生活中必不可少的,在节约用水的倡导下,各地的自来水公司也在根据各地用水量的情况,调整水费来控制各地的用水量,而在python的帮助下,我们能很轻易的计算出居民一个月的水费。
1 问题
为鼓励居民节约用水,自来水公司采取按用水量阶梯式计价的办法,居民应该交水费y(元)与月用水量x(吨)相关,当x不超过15吨时,y=4x/3;超过后,y=2.5x-17.5。请编写程序实现水费的计算。(输入格式:输入一行中给出非负实数x;输出格式:在一行输出应交的水费,精确到小数点后2位。)
2 方法
在键盘输入本月用水量x,运用if语句,判断本月用水是否大于等于15吨或者是小于15吨,并计算出本月水费y的值并输出,之后输出本月应交的水费。
3 实验结果与讨论
通过理论的成立并进行实验之后,可以很容易的计算出水费。
代码清单 1
| x = int(input('请输入本月的用水量:')) if x <= 15: y = 4 * x / 3 print('本月需要缴纳的水费为:{:.2f}元'.format(y)) else: y = 2.5 * x - 17.5 print('本月需要缴纳的水费为:%.2f元'%(y)) |
4 结语
在这个快生活节奏的时代,python在生活中的运用,会极大的提高我们的办事效率,节省时间。
边栏推荐
- 【图论常见模板题】4种最短路解法和2种最小生成树解法
- Wechat games (3)
- Wx applet vant UI call interface to realize two-level cascade
- Fmdb usage details mark
- MySQL transactions
- Asynchronous sending and receiving of message passing based concurrent programming (MPI)
- Model electricity experiment -- Experiment 1 transistor common emitter single transistor amplifier
- Expérience électrique en mode - - expérience 2 circuit d'amplification de source commune JFET
- Common array operations in JS
- 目标检测系列——开山之作RCNN原理详解
猜你喜欢
随机推荐
4、 Button component
Leetcode 172 Zero after factorial (2022.06.21)
Concurrent programming summary
LNMP environment setup
Download addresses of Xcode versions
[multi thread programming] thread scheduling strategy and priority
【宋红康 MySQL数据库 】【高级篇】【06】MySQL的逻辑架构
Ffmpeg pit
MySQL query group by 1055 is the simplest and most convenient way to solve the problem perfectly
Wechat applets will directly open the parent element when the child element of flex:1 is too long (the text is too long)
How Navicat queries the password information of the connected database
Microsoft Remote Desktop 10.7.6 official
Wechat games (5)
Realization of readable and writable files in library management system with C language bidirectional linked list
FFMPEG坑
An example shows the difference between let and VaR
Wx applet vant UI call interface to realize two-level cascade
setneedsdisplay layoutifneeded setNeedsLayout
Expérience électrique en mode - - expérience 2 circuit d'amplification de source commune JFET
Kotlin a simple Android program








![[普通物理]波的能量与干涉](/img/fe/066aa9e8ed776b8f069b59b7123367.png)
