1.3分支结构(一)
第1关 整除判断
![](https://i-blog.csdnimg.cn/blog_migrate/50281aa1cb939e9de83a50e9251b6c85.png)
第2关 币种转换
![](https://i-blog.csdnimg.cn/blog_migrate/172f6d569a07ee142bfbfb7ab8c91779.png)
第3关 求最大值
为什么这题会出现在这里?为了让我们放松一下?
![](https://i-blog.csdnimg.cn/blog_migrate/ff38d248477ab65ee83fcb54391a3174.png)
第4关 分段计程票价
![](https://i-blog.csdnimg.cn/blog_migrate/76362f12b0db4ea9c3c5bbb8a08240d6.png)
1.3 分支结构(二)
第1关 分段函数
![](https://i-blog.csdnimg.cn/blog_migrate/79eaa969d97648b85af1270f1ea417b6.png)
第2关 输入年月输出该月的天数
![](https://i-blog.csdnimg.cn/blog_migrate/75f0087801d217d3e300da0b3a43d763.png)
第3关 判断三角形类型
![](https://i-blog.csdnimg.cn/blog_migrate/eee57c410f9a82c150f4071e2e4ee2e8.png)
第4关 根据身份证号判断是否到了合法结婚年龄
#根据身份证号判断是否到了合法结婚年龄
id= input() #输入身份证号码
#代码开始
a=len(id)
if a != 18:
print("身份证号错误")
else:
b=int(id[16])
c=int(id[6:10])
if b % 2 == 0:
print("性别:女")
if c <= 2002:
print("达到合法结婚年龄")
else:
print("未到合法结婚年龄")
#姐姐们妇女节快乐~
else:
print("性别:男")
if c <= 2000:
print("达到合法结婚年龄")
else:
print("未到合法结婚年龄")
#代码结束
第5关 计算每月水费
这题我花的时间比前8关加起来还多。
#计算每月水费
last=eval(input("上月水表读数(吨):"))
current=eval(input("本月水表读数(吨):"))
number=eval(input("家庭人数:"))
low_income=input("是否低保(y/n):")
amount=0 #每月用水吨数
money=0 #每月水费
#代码开始
if number <= 4:
if low_income == 'y':
amount = current - last -6
if amount < 0:
money = 0
elif 0 < amount <= 15:
money = 2.88 * amount
elif 15 < current <= 22:
money = 3.64 * (amount - 15) + 43.2
else:
money = 4.39 * (amount - 22) + 68.68
else:
amount = current - last
if amount < 15:
money = 2.88 * amount
elif 15 < amount < 22:
money = 3.64 * (amount - 15) + 43.2
else:
money = 4.39 * (amount - 22) + 68.68
else:
if low_income == 'y':
amount = current - last - 6
if amount < 0:
money = 0
elif amount <= 15:
money = 2.88 * amount
elif 15 < amount <= 22:
money = 43.2 + (amount - 15) * 3.64
else:
money = 68.68 + 4.39 * (amount - 22)
else:
amount = current - last
a = amount / number
if a <= 4:
money = amount * 2.88
elif 4 < a <= 5:
money = 2.88 * number * 4 + (a - 4) * number * 3.64
else:
money = 2.88 * number * 4 + 3.64 * number + (a - 5) * 4.39 * number
print("本月用水吨数(减免后){:.2f}吨,水费{:.2f}元".format(amount,money))