初学者Python“无”问题

2023-12-03

我刚刚开始使用 python,自从我开始了一个新的计算器项目以来,pyCharm 在所有内容之后都没有吐出任何内容。我不确定是什么导致了这个错误,如果我能在这里得到一些帮助,我将不胜感激。 (这只是我展示的主要功能)这是代码:

def main():
    run = True
    while run == True:
        if run == False:
        break
    try:
        operation = input(print("Would you like to *, -, + or /?"))

        if operation != "+" and operation != "-" and operation != "/" and operation != "*":
            print("invalid input.")
            go = input(print("Would you like to continue, yes or no?"))

        if go == "no":
            run = False

        else:
            continue

        else:
            num1 = int(input(print("What's your first number?")))

            num2 = int(input(print("What's your second number?")))

         if operation == "*":
            print(multi(num1, num2))

         if operation == "-":
            print(sub(num1, num2))

         if operation == "+":
               print(add(num1, num2))

         if operation == "/":
               print(div(num1, num2))

         go = input(print("Would you like to make another calculation, yes or no?"))
         if go == "no":
                run = False
                else:
                    continue

        except:
            print("invalid input.")
            go = input(print("Would you like to continue, yes or no?"))
            if go == "no":
                run = False
            else:
               continue

发生情况的示例:

Would you like to *, -, + or /?
None/
What's your first number?
None3
What's your second number?
None4
0.75
Would you like to make another calculation, yes or no?
Noneno

Process finished with exit code 0

Remove print声明来自input calls:

input(print("What's your first number?")) -> input("What's your first number?\n") or input("Your first number: ")

That None是返回值print显示的功能input功能。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

初学者Python“无”问题 的相关文章

随机推荐