当前位置:网站首页>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 :
边栏推荐
猜你喜欢
[wp]bmzclub writeup of several questions
我国算力规模排名全球第二:计算正向智算跨越
[wp][introduction] brush weak type questions
Test d'automatisation de l'interface utilisateur télécharger manuellement le pilote du navigateur à partir de maintenant
It took two nights to get Wu Enda's machine learning course certificate from Stanford University
为什么百度、阿里这些大厂宁愿花25K招聘应届生,也不愿涨薪5K留住老员工?
Longyuan war "epidemic" 2021 network security competition web easyjaba
Uni app change the default component style
EasyCVR平台出现WebRTC协议视频播放不了是什么原因?
Common features of ES6
随机推荐
快手、抖音、视频号交战内容付费
Open graph protocol
10种寻址方式之间的区别
[PHP features - variable coverage] improper use, improper configuration and code logic vulnerability of the function
UI自动化测试从此告别手动下载浏览器驱动
web资源部署后navigator获取不到mediaDevices实例的解决方案(navigator.mediaDevices为undefined)
Basic function learning 02
Test d'automatisation de l'interface utilisateur télécharger manuellement le pilote du navigateur à partir de maintenant
Technical tutorial: how to use easydss to push live streaming to qiniu cloud?
MindFusion.Virtual Keyboard for WPF
企业级:Spire.Office for .NET:Platinum|7.7.x
@The problem of cross database query invalidation caused by transactional annotation
Operation flow of UE4 DMX and grandma2 onpc 3.1.2.5
Installation of postman and postman interceptor
IronXL for .NET 2022.6
Threejs realizes the drawing of the earth, geographical location annotation, longitude and latitude conversion of world coordinates threejs coordinates
Seven join join queries of MySQL
It took two nights to get Wu Enda's machine learning course certificate from Stanford University
Is there a sudden failure on the line? How to make emergency diagnosis, troubleshooting and recovery
基于TCP的移动端IM即时通讯开发仍然需要心跳保活