当前位置:网站首页>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 :
边栏推荐
- 10种寻址方式之间的区别
- Use of vscode software
- Learning notes 8
- 3. Package the bottom navigation tabbar
- 学习MVVM笔记(一)
- @The problem of cross database query invalidation caused by transactional annotation
- What is test development? Why do so many companies hire test developers now?
- 特殊版:SpreadJS v15.1 VS SpreadJS v15.0
- Resolved (sqlalchemy+pandas.read_sql) attributeerror: 'engine' object has no attribute 'execution_ options‘
- NEW:Devart dotConnect ADO. NET
猜你喜欢
@The problem of cross database query invalidation caused by transactional annotation
A real day for Beijing programmers!!!!!
Use threejs to create geometry, dynamically add geometry, delete geometry, and add coordinate axes
企业级:Spire.Office for .NET:Platinum|7.7.x
Seven join join queries of MySQL
How to solve the problem that easycvr changes the recording storage path and does not generate recording files?
网络安全-记录web漏洞修复
Threejs realizes sky box, panoramic scene, ground grass
面试字节,过关斩将直接干到 3 面,结果找了个架构师来吊打我?
Online sql to excel (xls/xlsx) tool
随机推荐
How does the applet solve the rendering layer network layer error?
Threejs factory model 3DMAX model obj+mtl format, source file download
网络安全-记录web漏洞修复
Longyuan war "epidemic" 2021 network security competition web easyjaba
面试字节,过关斩将直接干到 3 面,结果找了个架构师来吊打我?
About the recent experience of writing questions
根据入栈顺序判断出栈顺序是否合理
MindFusion. Virtual Keyboard for WPF
Rome链分析
Study notes 7
Learning notes 8
[wp]bmzclub writeup of several questions
Online sql to excel (xls/xlsx) tool
web资源部署后navigator获取不到mediaDevices实例的解决方案(navigator.mediaDevices为undefined)
The order of LDS links
【刷题】BFS题目精选
Online text line fixed length fill tool
Threejs loads the city obj model, loads the character gltf model, and tweetjs realizes the movement of characters according to the planned route
@Transactional 注解导致跨库查询失效的问题
Clickpaas low code platform