Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/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 - Fatal编程技术网

python程序中的语法无效

python程序中的语法无效,python,Python,我刚开始学习python,我编写了一个程序,为欧洲彩票提供一组数字。彩票由5个所谓的数字组成,你必须从1到50的数字中选择,还有2个所谓的星星,你必须从1到11的数字中选择。它工作正常,但我希望它能够从用户那里获取输入,告诉用户需要多少组数字和星星,然后打印所有这些数字和星星。但是,我得到一个无效的语法错误。节目如下: import random print "This program doesn't increase the chances of winning the lottery!"

我刚开始学习python,我编写了一个程序,为欧洲彩票提供一组数字。彩票由5个所谓的数字组成,你必须从1到50的数字中选择,还有2个所谓的星星,你必须从1到11的数字中选择。它工作正常,但我希望它能够从用户那里获取输入,告诉用户需要多少组数字和星星,然后打印所有这些数字和星星。但是,我得到一个无效的语法错误。节目如下:

import random

print "This program doesn't increase the chances of winning the lottery!"

numbers=range(1, 51)

stars=range(1,12)

sets=int(raw_input("Insert number of sets here")

for i in range(sets+1): 

        a=sorted(random.sample(numbers, 5))
        print "The numbers are", a
        b=sorted(random.sample(stars, 2))       
        print "The stars are", b

print "Good luck!"           

外壳突出了冒号,但我不知道为什么?提前感谢您的帮助。

当Python解释器引发SyntaxError时,它将指示它识别出语法错误的行,甚至是行内的位置

然而,实际的语法错误通常发生在Python意识到存在语法错误的位置之前的某个点,因为代码在语法上是有效的,即使它不是预期的

在本例中,缺少一个右括号:

sets=int(raw_input("Insert number of sets here")  # <-- Add `)` here to fix.

请注意,有括号和大括号高亮显示,这可以帮助您查看它们关闭的位置和时间。Emacs和vim是两种流行的选择。

使用ide或linter来发现语法错误。谢谢。我现在觉得很傻。