当前位置:网站首页>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 :
边栏推荐
- Soul 3: what is interface testing, how to play interface testing, and how to play interface automation testing?
- Ctfshow web entry code audit
- 线上故障突突突?如何紧急诊断、排查与恢复
- 一文带你了解BI的前世今身与企业数字化转型的关系
- Threejs rendering obj+mtl model source code, 3D factory model
- UI自动化测试从此告别手动下载浏览器驱动
- 输入的查询SQL语句,是如何执行的?
- Excuse me, my request is a condition update, but it is blocked in the buffer. In this case, can I only flush the cache every time?
- Technical tutorial: how to use easydss to push live streaming to qiniu cloud?
- @Transactional 注解导致跨库查询失效的问题
猜你喜欢
CTF stegano practice stegano 9
Alibaba cloud ECS uses cloudfs4oss to mount OSS
What is the reason why the webrtc protocol video cannot be played on the easycvr platform?
Online text line fixed length fill tool
NEW:Devart dotConnect ADO.NET
About the recent experience of writing questions
在线文本行固定长度填充工具
Common features of ES6
10种寻址方式之间的区别
IronXL for .NET 2022.6
随机推荐
provide/inject
Use threejs to create geometry and add materials, lights, shadows, animations, and axes
It took two nights to get Wu Enda's machine learning course certificate from Stanford University
kubernetes集群之调度系统
[wp]bmzclub writeup of several questions
【看完就懂系列】一文6000字教你从0到1实现接口自动化
Possible stack order of stack order with length n
Threejs realizes rain, snow, overcast, sunny, flame
MacBook安装postgreSQL+postgis
The order of LDS links
PlasticSCM 企业版Crack
Special Edition: spreadjs v15.1 vs spreadjs v15.0
Clickpaas low code platform
Uni app change the default component style
Threejs factory model 3DMAX model obj+mtl format, source file download
@Transactional 注解导致跨库查询失效的问题
Containerization Foundation
Ctfshow web entry code audit
Threejs realizes the drawing of the earth, geographical location annotation, longitude and latitude conversion of world coordinates threejs coordinates
DMX parameter exploration of grandma2 onpc 3.1.2.5