gpt4 book ai didi

Python input() 函数无法正常运行 : doesn't seem to record any input. 也许是 Linux 问题?

转载 作者:太空宇宙 更新时间:2023-11-04 05:55:41 25 4
gpt4 key购买 nike

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

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 input() 函数无法正常运行 : doesn't seem to record any input. 也许是 Linux 问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55137138/

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