我如何摆脱这里的术语 none 它是什么?
How do i get rid of the term none here and what is it?
我已经创建了一个基本的加法语句,我知道输入被读取为一个字符串,但我的代码在接受输入之前打印出“none”(见下文)。我如何将整数作为输入??
# code example
print("This is a calculator")
a = input(print("Enter the first number"))
b = input(print("Enter the second number"))
print("sum =", a + b)
这输出:
This is a calculator
Enter the first number
None5
Enter the second number
None6
sum = 56
input()
为您打印提示。您只需输入 a = input("Enter the first number")
去掉前两行的print()
:
a = input("Enter the first number")
b = input("Enter the second number")
而不是:
a = input(print("Enter the first number"))
b = input(print("Enter the second number"))
None
是 print()
函数的 return 所以因为 input()
打印你输入的内容所以你正在打印 returned None
值。然后打印语句仍然会打印提示。但是,您想让 input()
如上所述打印提示。
我已经创建了一个基本的加法语句,我知道输入被读取为一个字符串,但我的代码在接受输入之前打印出“none”(见下文)。我如何将整数作为输入??
# code example
print("This is a calculator")
a = input(print("Enter the first number"))
b = input(print("Enter the second number"))
print("sum =", a + b)
这输出:
This is a calculator
Enter the first number
None5
Enter the second number
None6
sum = 56
input()
为您打印提示。您只需输入 a = input("Enter the first number")
去掉前两行的print()
:
a = input("Enter the first number")
b = input("Enter the second number")
而不是:
a = input(print("Enter the first number"))
b = input(print("Enter the second number"))
None
是 print()
函数的 return 所以因为 input()
打印你输入的内容所以你正在打印 returned None
值。然后打印语句仍然会打印提示。但是,您想让 input()
如上所述打印提示。