Question

function error removal

Posted June 4, 2021 72 views
Python
def my_func():
    input_pressure = float(input("Enter pressure in psi: "))
    print("Value inside function:",input_pressure)
my_func()
# conv_press = input_pressure/14.6;
print("Value outside function:",+input_pressure/14.6)
edited by bobbyiliev
1 comment
  • def my_func():
        input_pressure = float(input("Enter pressure in psi: "))
        print("Value inside function:",input_pressure)
    my_func()
    # conv_press = input_pressure/14.6;
    print("Value outside function:",+input_pressure/14.6)
    
    edited by bobbyiliev

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
1 answer

Hi there,

Usually, variables defined inside a specific function are not accessible outside of that function.

This should work with the following syntax by attaching the variable to an object so it could be accessible outside of the function:

def my_func():
    my_func.input_pressure = float(input("Enter pressure in psi: "))
    print("Value inside function:",my_func.input_pressure)
my_func()

print("Value outside function:",+my_func.input_pressure/14.6)

Hope that this helps.
Regards,
Bobby