gpt4 book ai didi

python - 如何根据 Python 中的输入答案计算条件?

转载 作者:太空宇宙 更新时间:2023-11-03 14:31:07 25 4
gpt4 key购买 nike

这个问题需要一些帮助。我在搜索中没有找到任何内容,但这可能是因为我不完全确定要问什么或定义问题。

我会在这里尝试这样做。

所以我想制作一个用于水肺潜水的 SAC 计算器。用拉门斯的话来说,这是一个基本上计算空气消耗量的计算器。

度量公式为 VT x VC/T/P = SAC更多信息请点击 https://www.divein.com/guide/know-your-air-consumption/

在计算空气消耗量时,我遇到了一些问题,因为我似乎需要以某种方式将用户的输入转换为值。

  • 用户回答问题:您的潜水深度是多少米(或英尺)?嗯,这非常简单,因为用户会回答,即 30 米/100 英尺。

但是,为了使计算器正常工作,我需要使用 ATM 模型进行计算。随着水下深度的增加,大气压力也会增加,如下图所示:

Pressure Example

因此,如果用户输入 30 米的值,我需要知道该答案的 ATM 值。

我尝试使用 if 语句来解决此问题,但我不认为这可能是更好的方法。

这是到目前为止的代码

    #SAC Rate Calculator
#This program will calculate your air consumption rate for scuba diving
#Made by Tom Knudsen - post@tknudsen.com
#License is open source

import os
import time

os.system('clear')
print('***********************************')
print('***********************************')
print('**********SAC Calculator***********')
print('****************by*****************')
print('************Tom Knudsen************')
print('***********************************')
print('***********************************')
print('')
print('')
print('Welcome to the SAC calculator')
time.sleep(1)

# This code is to first determain the air consumption in bar)
print('First we need to calculate your air consumption in bar')
tankVolum = input('How large is your tank in litres? :')
startBar = input('Please enter your start pressure in BAR: ') #starting pressure with full cooled tank
endBar = input('Please enter your end pressure in BAR: ') #ending pressure with cooled tank
totalBar = startBar - endBar
time.sleep(2)
print('Thank you, your total pressure used is: ') #feedback to the user
print(totalBar)
time.sleep(3)
os.system('clear')
# Input to calculate air consumption in litres
print("Let's now see how much Surface Air Concumption in litre you used!")
time.sleep(2)
print('First we need to know a little bit about your dive :')
time.sleep(2)
depth = input('How deep was your dive in meter? :')
time.sleep(2)
diveTime = input('How long was your dive in minutes? :')
time.sleep(2)
print('Let me calculate, please wait...')


#this is my test, I do not know how to get "depthTotal" as this calue equals ATM pressure and P in the equation formula above.
if depth <= 10:
a = 2
elif depth >10 and <= 20:
b = 3
elif depath >20 and <= 30:
c = 4
else:
print('You need to enter a depth between 0 and 40 meter')



sacResults = tankVolum x totalBar / diveTime / depthTotal

# Example = 12 Liter x 150 bar used / 46 minutes dive time / 30 meter depth
# sacResults = 12 * 150 / 46 / 3

最佳答案

解决问题的最简单方法是执行以下操作:

#this is my test, I do not know how to get "depthTotal" as this calue equals ATM pressure and P in the equation formula above.

depth_total = None
if depth <= 10:
depth_total = 2
elif depth >10 and <= 20:
depth_total = 3
elif depath >20 and <= 30:
depth_total = 4
else:
print('You need to enter a depth between 0 and 40 meter')

sacResults = tankVolum x totalBar / diveTime / depthTotal

您可以用更简单的方式做到这一点,因为 ATM 似乎与深度成正比(每 33 英尺 1 巴压力),您可以创建一个将深度转换为 ATM 的简单函数:

def depth_to_atm(depth_in_meters):
(depth_in_meters*3.2808)/ 33 # apparently 1 bar equals 33 feet of water
# (3.2808 is how many feet there are in a meter)

并在您的公式中使用该函数。

关于python - 如何根据 Python 中的输入答案计算条件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47285790/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com