Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/303.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 如何修复“while”语句中的语法错误?_Python_Python 3.x_Loops_Syntax Error_Conditional - Fatal编程技术网

Python 如何修复“while”语句中的语法错误?

Python 如何修复“while”语句中的语法错误?,python,python-3.x,loops,syntax-error,conditional,Python,Python 3.x,Loops,Syntax Error,Conditional,我正在为我的书制作书架的代码,我正在制作一个条件,条件是:当x变量小于y变量时,继续,否则,中断,但是python说在这行中,有一个语法错误,但是,我不理解错误在哪里 我尝试重新运行代码,验证标识空间,等等,但对我来说,没有什么错,而对于python来说,有一个语法错误 def lista() cadastrados = 0 livros = int(input("Quantos livros você deseja cadastrar?") while cadastr

我正在为我的书制作书架的代码,我正在制作一个条件,条件是:当x变量小于y变量时,继续,否则,中断,但是python说在这行中,有一个语法错误,但是,我不理解错误在哪里

我尝试重新运行代码,验证标识空间,等等,但对我来说,没有什么错,而对于python来说,有一个语法错误

def lista()
    cadastrados = 0 
    livros = int(input("Quantos livros você deseja cadastrar?")
    while cadastrados < livros:
        print()
        linha()
        print()
        print()
        título = input("Put the title of your book: ")
        autor = input("Put the writer of your book: ")
        gênero = input("Put the gender of your book: ")
        cadastrados += 1
        if cadastrados >= livros:
            break

我期待问题的循环,并将数字添加到cadastrados变量,如果数字达到极限,while循环将停止,但实际结果是突出显示while语句的无效语法

您错过了一个闭合括号

livros = int(input("Quantos livros você deseja cadastrar?")
应该是

livros = int(input("Quantos livros você deseja cadastrar?"))

第2行缺少括号;