python两列时间间隔计算器,Python“距离/时间/燃油计算器”帮助2
我有一個(gè)工作程序,根據(jù)我輸入的信息,詢(xún)問(wèn)我想行駛多遠(yuǎn)(在幾個(gè)問(wèn)題中),并計(jì)算出我的旅行將持續(xù)多長(zhǎng)時(shí)間,以及我將燃燒多少燃料。在
現(xiàn)在-我想在程序中使用插入時(shí)間而不是距離的選項(xiàng),這樣我就可以說(shuō)我想以某個(gè)速度行駛多少分鐘(而不是多少公里),然后程序?qū)⒂?jì)算并打印-這次-根據(jù)所有輸入的行駛距離。。。
盡管如此,我認(rèn)為代碼本身可能會(huì)解釋我的最佳含義:
1.以下是迄今為止只有“距離”輸入的工作代碼:while True:
# Get fuel remaining in the tank from the user
fuel_tank = input("Enter fuel remaining:")
fuel_tank = float(fuel_tank)
# Get L/100km used from the user
fuel = input("Enter car's L/100kmh:")
fuel = float(fuel)
# Get distance driven from the user
distance = input("Enter kilometers driven:")
distance = float(distance)
# Get speed used from the user
speed = input("Enter driving speed:")
speed = float(speed)
# Calculate and print the answer
time = distance / speed
fuel_burned = distance / 100 * fuel
fuel_remaining = fuel_tank - fuel_burned
hours = int(time)
minutes_remainder = (time - hours) * 60
minutes = int(minutes_remainder)
print("-----------------------------------------")
print("Time traveled: ", hours,"h:",minutes,"min")
print("Fuel burned: ", fuel_burned," liters")
print("==========================================")
print("Fuel remaining: ", fuel_remaining," liters")
print("==========================================")
again = input("Go again? (y/n)")
if again == "n":
break
2.這是我試圖做的修改(當(dāng)然,這不起作用):
^{pr2}$
有人知道怎么做嗎?在
總結(jié)
以上是生活随笔為你收集整理的python两列时间间隔计算器,Python“距离/时间/燃油计算器”帮助2的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 2018-2020最新Google开源镜
- 下一篇: Python的数据科学函数包(二)——p