Python input()函数无法正常运行:似乎未记录任何输入。也许是Linux问题? - python

            
                    
我在运行我编写的代码时似乎遇到了问题:

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)

如果输入数字2,则应转到函数acidhenderson()(我没有放置其他函数,因为这会占用很多空间),但是在linux中,它只是返回到下一行,如下所示:

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#

我是Linux的新手,但我认为这可能是Linux问题,而不是python代码问题,但我不太确定。有人可以帮忙吗?

参考方案

最佳照片,您正在使用:

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

Python uuid4,如何限制唯一字符的长度 - python

在Python中,我正在使用uuid4()方法创建唯一的字符集。但是我找不到将其限制为10或8个字符的方法。有什么办法吗?uuid4()ffc69c1b-9d87-4c19-8dac-c09ca857e3fc谢谢。 参考方案 尝试:x = uuid4() str(x)[:8] 输出:"ffc69c1b" Is there a way to…

Python-crontab模块 - python

我正在尝试在Linux OS(CentOS 7)上使用Python-crontab模块我的配置文件如下:{ "ossConfigurationData": { "work1": [ { "cronInterval": "0 0 0 1 1 ?", "attribute&…

Python:检查是否存在维基百科文章 - python

我试图弄清楚如何检查Wikipedia文章是否存在。例如,https://en.wikipedia.org/wiki/Food 存在,但是https://en.wikipedia.org/wiki/Fod 不会,页面只是说:“维基百科没有此名称的文章。”谢谢! 参考方案 >>> import urllib >>> prin…

比较用户输入和关键词列表 - python

我想通过功能接收用户输入并将其与关键字列表进行比较,如果用户输入的任何单词与关键字匹配,则满足条件并中断循环。如果没有一个单词与关键字匹配,则控制台再次要求输入。我一直在处理此循环,或者不管是否遇到关键字都让它不断地要求输入,或者验证每个输入的单词。任何有关如何纠正它的建议将不胜感激。def validated_response(user_complaint…

Python Pandas导出数据 - python

我正在使用python pandas处理一些数据。我已使用以下代码将数据导出到excel文件。writer = pd.ExcelWriter('Data.xlsx'); wrong_data.to_excel(writer,"Names which are wrong", index = False); writer.…