Beginner python “None” issue

后端 未结 3 1884
说谎
说谎 2021-01-15 04:27

I just started on python and since I started a new calculator project, pyCharm spits out none after everything. I\'m not sure what\'s causing this error, I would appreciate

相关标签:
3条回答
  • 2021-01-15 05:00

    The function signature for input is input([prompt]). The brackets indicate that a prompt is optional but basically input is expecting you to give a string to print out. Instead, you are giving it a print() statement. The return value of a print statement is None so that's getting outputted as the prompt by the input statement.

    Note, it is also bad practice to have an except statement without specifying an error type. Without specifying a type, the except will trigger for any error (for example, it triggered when I tried running your code before adding in your functions like multi). I think you want except ValueError here.

    0 讨论(0)
  • 2021-01-15 05:03

    Try removing the print statement in the input.
    Instead of input(print("Would you like to continue, yes or no?")) , Try
    input("Would you like to continue, yes or no?")
    That is what i do

    0 讨论(0)
  • 2021-01-15 05:16

    Remove print statements from input calls:

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

    That None is the return value of print function that is displayed by input function.

    0 讨论(0)
提交回复
热议问题