Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
变量名给出语法错误(Python)_Python_Variables_Syntax Error - Fatal编程技术网

变量名给出语法错误(Python)

变量名给出语法错误(Python),python,variables,syntax-error,Python,Variables,Syntax Error,我做的一个简单的程序有问题 num2 = 0 num1 = 1 print ("Enter a number one after another to sum them up, and when you're done type 0") while num1 != 0: num1 = float(raw_input ("Please enter a number:") num2 += num1 if num1 == 0: print

我做的一个简单的程序有问题

num2 = 0
num1 = 1
print ("Enter a number one after another to sum them up, and when you're done type 0")
while num1 != 0:
    num1 = float(raw_input ("Please enter a number:")
    num2 += num1
if num1 == 0:
    print ("The sum of the numbers is:" + str(num2))
出于某种原因,
num2+=num1
行在
num2
上给了我一个语法错误,您错过了一个
,右括号,如下所示:

    num1 = float(raw_input ("Please enter a number:")
    num1 = float(raw_input ("Please enter a number:"))
应该是

您错过了一个
,右括号,如下所示:

    num1 = float(raw_input ("Please enter a number:")
    num1 = float(raw_input ("Please enter a number:"))
应该是


你应该使用一个编辑器,当出现明显的语法错误,比如不平衡的括号时,它会显示出来。我想Idle会标记这种东西。我将NetBeans用于python、java和PHP。它能理解大多数语法。我想我记得在我的一些第一个程序中它做到了。可能是出了什么问题,或者可能是我记不清了。你应该使用一个编辑器,当出现明显的语法错误时,比如不平衡的括号时,它会向你显示。我想Idle会标记这种东西。我将NetBeans用于python、java和PHP。它能理解大多数语法。我想我记得在我的一些第一个程序中它做到了。可能是出了什么问题,或者可能是我记不清了。添加一点解释,解释为什么OP的代码不起作用,以及为什么你的代码更好会有帮助。此代码甚至与OP的问题无关,仍然存在完全相同的语法错误。添加一点解释,解释为什么OP的代码不起作用,以及为什么你的代码更好会有帮助help此代码甚至与OP的问题无关,仍然存在完全相同的语法错误。