当前位置:网站首页>Fuel consumption calculator
Fuel consumption calculator
2022-07-05 04:06:00 【Fantasy elves_ cq】
Fuel consumption calculator
Exercise questions

My code running effect
My problem solving code
( If you can't make clear the function from the statement annotation , Please leave a message in the comment area for advice and discussion .)
# coding: utf-8
''' Please pay attention to Walrus operator is used in fuel consumption calculation expression := (3.9+ python Version specific operators ), Such as expression code Please do not make any changes in Python 3.9+ Environment is running .'''
def error():
s = ''' Error message printing '''
print(f'\n\n\n{
s:=^36}\n\n\
{
" Input error ! Please try again .":^33}\n\n\
{
"":*^42}\n')
s = ''' The state of two refuels must be consistent , To accurately calculate the fuel consumption . Last time “ Fill it up with ” perhaps “ The oil gauge lights up ” when , Record the mileage , Wait until again “ Fill it up with ” perhaps “ The oil gauge lights up ” when , The interval can be calculated accurately Fuel consumption . The last time “ The oil gauge lights up ” Fuel filling volume at , namely It was last time “ The oil gauge lights up ” This time “ The oil gauge lights up ” Mileage used ; This time, “ Fill it up with ” Refueling volume of , Last time “ Fill it up with ” Here we are “ Fill it up with ” Mileage Use oil .'''
print(f'\n\n\n{" Fuel consumption calculation ":_^38}')
s = '1. Fill the tank ', '2. The oil gauge lights up '
while True:
print(f'\n{"":.^42}\n\n{" ".join(s):^34}\n\n{".":.>42}')
k = input(f'{" Please select the fuel tank status :":>12}')
if k not in ('1', '2'):
error()
else:
k = s[k := int(k) - 1][3:]
break
# Enter mileage
milage_last, milage_local = map(float, (input(f'\n{s:>10}:') for s in (f" The last time {k} The mileage ", f' This time, {k} The mileage ')))
# Enter the oil price and refueling amount
oil_price, sum_of_money = map(float, (input(f'\n{s:>10}:') for s in (" Oil price in the service station ", ' Refueling amount ')))
# Calculate fuel consumption ( Use of the python 3.9+ Walrus operators supported )
oil_wear = ((sum_oil := sum_of_money / oil_price)\
/ (sum_milage := milage_local - milage_last)\
) * 100
print(f'\n\n\n{
" Conditions for accurate fuel consumption calculation ":.^33}\
\n\n{
s}\
\n\n{
" Conditions for accurate fuel consumption calculation ":.^33}')
print(f'\n\n\n{
" Fuel consumption calculator ":_^37}\
\n\n\n{
" Last mileage :":>15}{
milage_last} km\
\n{
" Current mileage :":>15}{
milage_local} km\
\n{
" Refueling status :":>15}{
k}\
\n{
" Fuel consumption mileage :":>15}{
sum_milage} km\n\
\n{
"Cut-off Rule":.^42}\n\
\n{
" Current oil prices :":>15}¥{
oil_price:.2f} element / l \
\n{
" Refueling amount :":>15}¥{
sum_of_money:.2f} element \
\n{
" Add oil The amount :":>16}{
sum_oil:.2f} l \n\
\n{
"Cut-off Rule":.^42}\n\
\n\n{
" Current fuel consumption :":>15}{
oil_wear:.2f} l /100km\
\n\n{
"":>19}¥ {
oil_price * oil_wear / 100:.2f} element /km\
\n\n\n{
"The End":_^42}\n')
my HOT Bo :
- “ Happy number ” Judge ( Current reading 1167)
- Roman digital converter ( Using Roman numerals to construct the value modulus of elements to realize )( Current reading 1222)
- Roman digital converter | Roman numeral generator ( Current reading 1450)
- Give Way QQ Magic code of group nickname color change ( Current reading 2602)
- Fibonacci sequence ( Recursive implementation and for Realization )( Current reading 1938)
- Find the repeated start and end positions of elements in the sorting array ( Current reading 1205)
- The largest rectangle in the histogram ( Current reading 1608)
- The letter combination of the telephone dialing keyboard ( Current reading 1227)
- Password strength detector ( Current reading 1671)
- Find the balance point of the list ( Current reading 1705)
- String statistics ( Current reading 2179)
- Nim game ( Code optimized version )( Current reading 826)
- Hot: Nim game ( Smart version starts )( Current reading 3248)
Recommended conditions Click to read a thousand Reference article :
A good writer recommends : Good habits of reliable programmers
Home 
Excellent articles :
- OPP The three major characteristics : In the package property
- Understand through built-in objects python'
- Regular expressions
- python in “*” The role of
- Python A complete self-study manual
- Walrus operators
- Python Medium `!=` And `is not` Different
- The right way to learn programming
source : Laoqi classroom
CSDN Practical skills blog :
边栏推荐
- Deflocculant aminoiodotide eye drops
- Threejs realizes rain, snow, overcast, sunny, flame
- Use object composition in preference to class inheritance
- How to solve the problem that easycvr changes the recording storage path and does not generate recording files?
- It took two nights to get Wu Enda's machine learning course certificate from Stanford University
- EasyCVR平台出现WebRTC协议视频播放不了是什么原因?
- Containerization Foundation
- MindFusion.Virtual Keyboard for WPF
- Deep learning - LSTM Foundation
- speed or tempo in classical music
猜你喜欢

25K 入职腾讯的那天,我特么哭了

Resolved (sqlalchemy+pandas.read_sql) attributeerror: 'engine' object has no attribute 'execution_ options‘

MacBook安装postgreSQL+postgis

官宣!第三届云原生编程挑战赛正式启动!

面试字节,过关斩将直接干到 3 面,结果找了个架构师来吊打我?

EasyCVR平台出现WebRTC协议视频播放不了是什么原因?

An elegant program for Euclid‘s algorithm

Rome chain analysis

Pyqt pyside custom telescopic menu bar sharing (including tutorial)

Online text line fixed length fill tool
随机推荐
EasyCVR更改录像存储路径,不生成录像文件如何解决?
网络安全-记录web漏洞修复
Installation of postman and postman interceptor
provide/inject
EasyCVR平台出现WebRTC协议视频播放不了是什么原因?
Judge whether the stack order is reasonable according to the stack order
根据入栈顺序判断出栈顺序是否合理
Threejs realizes rain, snow, overcast, sunny, flame
Summary of scene design
Clickhouse materialized view
How is the entered query SQL statement executed?
灵魂三问:什么是接口测试,接口测试怎么玩,接口自动化测试怎么玩?
Soul 3: what is interface testing, how to play interface testing, and how to play interface automation testing?
Open graph protocol
我就一写代码的,王总整天和我谈格局...
面试汇总:这是一份全面&详细的Android面试指南
Containerization Foundation
NEW:Devart dotConnect ADO.NET
DMX parameter exploration of grandma2 onpc 3.1.2.5
学习MVVM笔记(一)