1

Need some help with this question. I did not find anything in the search, but that can be because I am not entirely sure on what to ask or define the problem.

I will try to do this here.

So I wanted to make a SAC Calculator for scuba diving. That is in lamens terms a calculator to calculate air consumption basically.

The formula for metric is VT x VC / T / P = SAC More info here https://www.divein.com/guide/know-your-air-consumption/

I ran into some issues when calculating the air consumption as it seems I need to convert in somehow the input from the user into a value.

  • The user answers the question, how deep was your dive in meters(or feet)? Well this is pretty straight forward as the user would answer i.e. 30 meters / 100 feet.

However for the calculator to work correctly, I would need to calculate using the ATM model. As depth increases under water, the atmospheric pressure also increases as seen in this image:

Pressure Example

So if the user enters a value of 30 meters, I need to know the ATM value for this answer.

I tried to make an if statement to fix this, but I do not belive this might be the better approach.

Here is the code so far

    #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
Tom Knudsen
  • 63
  • 1
  • 8
  • Possible duplicate of [How can I read inputs as integers?](https://stackoverflow.com/questions/20449427/how-can-i-read-inputs-as-integers) – MB-F Nov 14 '17 at 12:28
  • Convert input values to `int` before using them in your calculations. – srikavineehari Nov 14 '17 at 12:40
  • "P = 3 (20 METERS OF WATER EQUALS 3 BARS OF PRESSURE)" so `P = depthTotal = depth * (3/20)` where `3/20` is the pressure increase per meter ... Not 100% sure if pressure is linear but [seems so](https://oceanservice.noaa.gov/facts/pressure.html) – urban Nov 14 '17 at 13:14

2 Answers2

1

The easiest way to fix your problem would be to do something like this:

#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

You can do it in a simpler way since it seems that the ATM are proportional to the depth (1 bar of pressure for every 33 feets), you could create a simple function converting depth into 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)

And use that function in your formula.

Valentin Calomme
  • 568
  • 1
  • 5
  • 17
0

The formula for calculating ATA is simple.

You don't need to use conditionals to figure this out, and by using this formula will give you a much more accurate representation of ATA.

ATA = depth / 10 + 1

Using this, when you're between whole numbers in depth you will get the correct ATA.

Llanilek
  • 3,386
  • 5
  • 39
  • 65