本帖最后由 paypojie 于 2022-5-14 11:21 编辑
Python 练习实例2
https://www.runoob.com/python/python-exercise-example2.html
我还是之前的解题思路 用笨办法写 看了题目 没看案例 直接撸代码
[Python] 纯文本查看 复制代码 num = int(input('请输入利润: '))
if num <= 100000:
q = num * 0.1
print(q)
elif 100000 < num <200000:
w = (num - 100000) * 0.075
q = 100000 * 0.1
w = w + q
print(w)
elif 400000 > num >= 200000:
e = (num - 200000) * 0.05
w = 100000 * 0.075
q = 100000 * 0.1
e = e + w + q
print(e)
elif 600000 > num >= 400000:
r = (num - 400000) * 0.03
e = 200000 * 0.05
w = 100000 * 0.075
q = 100000 * 0.1
r = r + e + w + q
print(r)
elif 1000000 > num >= 600000:
t = (num - 600000) * 0.015
r = 200000 * 0.03
e = 200000 * 0.05
w = 100000 * 0.075
q = 100000 * 0.1
t = t + r + e + w + q
print(t)
else:
y = (num -1000000) * 0.01
t = 400000 * 0.015
r = 200000 * 0.03
e = 200000 * 0.05
w = 100000 * 0.075
q = 100000 * 0.1
y = y + t + r + e + w + q
print(y)
上面是我第一次写的 下面是我改为函数形式的写法
[Python] 纯文本查看 复制代码 num = int(input('请输入利润: '))
a = 100000
def ll(num,a):
q = num * 0.1
w = (num - a) * 0.075
e = (num - 2*a) * 0.05
r = (num - 4*a) * 0.03
t = (num - 6*a) * 0.015
y = (num -10*a) * 0.01
if num <= a:
print(q)
elif a < num < 2*a:
w = w + a * 0.1
print(w)
elif 4*a > num >= 2*a:
w = a * 0.075
q = a * 0.1
e = e + w + q
print(e)
elif 6*a > num >= 4*a:
e = 2*a * 0.05
w = a * 0.075
q = a * 0.1
r = r + e + w + q
print(r)
elif 10*a > num >= 6*a:
r = 2*a * 0.03
e = 2*a * 0.05
w = a * 0.075
q = a * 0.1
t = t + r + e + w + q
print(t)
else:
t = 4*a * 0.015
r = 2*a * 0.03
e = 2*a * 0.05
w = a * 0.075
q = a * 0.1
y = y + t + r + e + w + q
print(y)
ll(num,a)
我刚开始自己写的时候想到了用逻辑来进行条件判断 有谁看出这段代码的瑕疵? |