当前位置:网站首页>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 :
边栏推荐
- Threejs realizes sky box, panoramic scene, ground grass
- Differences among 10 addressing modes
- The scale of computing power in China ranks second in the world: computing is leaping forward in Intelligent Computing
- MacBook安装postgreSQL+postgis
- About the project error reporting solution of mpaas Pb access mode adapting to 64 bit CPU architecture
- 技术教程:如何利用EasyDSS将直播流推到七牛云?
- Rust区块琏开发——签名加密与私钥公钥
- Why do big companies such as Baidu and Alibaba prefer to spend 25K to recruit fresh students rather than raise wages by 5K to retain old employees?
- @Transactional 注解导致跨库查询失效的问题
- Un réveil de l'application B devrait être rapide
猜你喜欢
Threejs implements labels and displays labels with custom styles
@The problem of cross database query invalidation caused by transactional annotation
Uni app change the default component style
The new project Galaxy token just announced by coinlist is gal
Threejs Internet of things, 3D visualization of factory
灵魂三问:什么是接口测试,接口测试怎么玩,接口自动化测试怎么玩?
How is the entered query SQL statement executed?
Resolved (sqlalchemy+pandas.read_sql) attributeerror: 'engine' object has no attribute 'execution_ options‘
DMX parameter exploration of grandma2 onpc 3.1.2.5
A real day for Beijing programmers!!!!!
随机推荐
Threejs clicks the scene object to obtain object information, and threejs uses raycaster to pick up object information
[Chongqing Guangdong education] 2408t Chinese contemporary literature reference test in autumn 2018 of the National Open University
FFmepg使用指南
Clickpaas low code platform
Interview summary: This is a comprehensive & detailed Android interview guide
PlasticSCM 企业版Crack
Three level linkage demo of uniapp uview u-picker components
Summary of scene design
Threejs rendering obj+mtl model source code, 3D factory model
Threejs realizes the drawing of the earth, geographical location annotation, longitude and latitude conversion of world coordinates threejs coordinates
Mixed compilation of C and CC
How to use jedis of redis
Judge whether the stack order is reasonable according to the stack order
JWT vulnerability recurrence
A application wakes up B should be a fast method
10种寻址方式之间的区别
Looking back on 2021, looking forward to 2022 | a year between CSDN and me
Wechat applet development process (with mind map)
我国算力规模排名全球第二:计算正向智算跨越
Rome chain analysis