-2

I'm seeming to have an issue with running this code that I made:

def acidhenderson():
    ka = input("Enter a Ka value:  ")
    pka = math.log(float(scientific_string(ka)), 10) * -1
    base = float(scientific_string(input("Enter base concentration:  ")))
    acid = float(scientific_string(input("Enter acid concentration:  ")))
    ph = pka + math.log((base / acid), 10)
    print("pH = " + str('%.2f' % ph) + ".")
    print("")
    main()

def main():
    print("1: Calculate pOH of a buffer from Kb (Henderson Hasselbalch equation)")
    print("2: Calculate pH of a buffer from Ka (Henderson Hasselbalch equation)")
    print("3: Calculate the ratio of base/acid from pH and Ka")
    print("4: Solve an ICE table")
    choice = input("What would you like to do?:  ")
    if choice == "1":
        basehenderson()
    if choice == "2":
        acidhenderson()
    if choice == "3":
        acid_base_ratio()
    if choice == "4":
        icesolver()
    if choice == "exit" or "quit":
        return
main()

def scientific_string(string):
    string_list = list(string)
    i = 0
    while i < len(string_list):
        if string_list[i] == "^":
            string_list[i] = "**"
            return_var = ''.join(string_list)
            return eval(return_var)
        i = i + 1
    return_var = ''.join(string_list)
    return eval(return_var)

If I input the number 2, it should go to the function acidhenderson() (I didn't put the other functions as it would take a lot of room), but instead in linux it just returns to the next line like this:

root@debian:~/Documents/code/eq# python equilibrium.py 
1: Calculate pOH of a buffer from Kb (Henderson Hasselbalch equation)
2: Calculate pH of a buffer from Ka (Henderson Hasselbalch equation)
3: Calculate the ratio of base/acid from pH and Ka
4: Solve an ICE table
What would you like to do?:  2
root@debian:~/Documents/code/eq#

I am relatively new to Linux but I'm thinking that this may be a Linux problem rather than a python code problem but I'm not too sure. Can anyone help?

Demitech
  • 1
  • 2

1 Answers1

-2

Best shot, you're using:

Python 2.x:

choice = raw_input("What would you like to do?:  ")  # to have the input in str
if choice == "1":
    basehenderson()
if choice == "2":
    acidhenderson()
if choice == "3":
    acid_base_ratio()
if choice == "4":
    icesolver()
if choice == "exit" or "quit":
    return
DirtyBit
  • 16,613
  • 4
  • 34
  • 55
  • Apparently, I was using 2.x and all I had to do to fix it was run python3 [filename] as I guess the default is to run 2.x since Debian comes preinstalled with both 2 and 3. – Demitech Mar 13 '19 at 08:38