# coding: utf-8
'''加油量计算使用了海象运算符 := ,
不作修改请在 Python 3.9+ 环境运行,
否则报错。'''
milage_last, milage_local = 4257, 4481
k = '上次加满'
oil_price, sum_of_money = 7.73, 200
oil_wear = ((sum_oil := sum_of_money / oil_price) / (sum_milage := milage_local - milage_last)) * 100
print(f'\n\n\n{"油耗计算器":_^37}\n\n\n{"上次里程:":>15}{milage_last} km\n{"当前里程:":>15}{milage_local} km\n{"加油状态:":>15}{k}\n{"油耗里程:":>15}{sum_milage} km\n\n{"Cut-off Rule":.^42}\n\n{"当前油价:":>15}¥{oil_price} 元/升\n{"加油金额:":>15}¥{sum_of_money} 元\n{"加 油 量:":>16}{sum_oil:.2f} 升\n\n{"Cut-off Rule":.^42}\n\n\n{"当前油耗:":>15}{oil_wear:.2f} 升/100km\n\n{"":>19}¥ {oil_price * oil_wear / 100:.2f} 元/km\n\n\n{"The End":_^42}\n')
# coding: utf-8
'''加油量计算使用了海象运算符 := ,
不作修改请在 Python 3.9+ 环境运行,
否则报错。'''
milage_last, milage_local = 4257, 4481
k = '上次加满'
oil_price, sum_of_money = 7.73, 200
oil_wear = ((sum_oil := sum_of_money / oil_price)\
/ (sum_milage := milage_local - milage_last)\
) * 100
print(f'\n\n\n{"油耗计算器":_^37}\
\n\n\n{"上次里程:":>15}{milage_last} km\
\n{"当前里程:":>15}{milage_local} km\
\n{"加油状态:":>15}{k}\
\n{"油耗里程:":>15}{sum_milage} km\n\
\n{"Cut-off Rule":.^42}\n\
\n{"当前油价:":>15}¥{oil_price} 元/升\
\n{"加油金额:":>15}¥{sum_of_money} 元\
\n{"加 油 量:":>16}{sum_oil:.2f} 升\n\
\n{"Cut-off Rule":.^42}\n\
\n\n{"当前油耗:":>15}{oil_wear:.2f} 升/100km\
\n\n{"":>19}¥ {oil_price * oil_wear / 100:.2f} 元/km\
\n\n\n{"The End":_^42}\n')
上一篇: 2021 ,邂逅 Python ,结缘 CSDN
下一篇:
来源:老齐教室