计算每月电费python

x, a = map(float,input().split())
if x > 50:
s = 50 * 0.53 + (x - 50) * 0.8
print("cost = {:.2f}".format(s))
else:
s = x * 0.53
print('cost = {:.2f}'.format(s))

img

img

(x - 50) * 0.8改成 (x - 50) * a

代码如下,有帮助点击一下采纳谢谢

total, each = input().split()
total = int(total)
each = float(each)
print(total, each)
cost = 0
if total > 50:
    cost = 50*0.53 + (total-50) * each
else:
    cost = 0.53 * total
print('cost = %.2f' % cost)