预计缩进块 - python

问题描述:

我在我的第一个编程cass,我想了解Python。从随机导入*预计缩进块 - python

def FillStudentsNames(): 

    studentNames = [] 
    for studentNames in range(1,11): 
     user_input = input("What is the students name? : ") 
     print(user_input) 


def FillStudentsGrades(): 
     studentGrades =[] 
     for studentGrades in range (1,11): 
      grade = randint(1,100) 
      print(grade) 

     return studentGrades 


def ShowData(studentNames, studentGrades): 
    counter = 0 
    studentNames=[] 
    studentGrades=[] 
    for counter in range(0,10): 

    def main(): 
    FillStudentsNames = StdNames 

    main() 

和我真的不知道为什么:

我已经得到了这些代码的缩进块。我缩进了“def main”,因为那是解析器显示错误的地方。现在我收到了同样的信息,但没有指出具体的空间。

你得到了错误,因为在def main行之前的for循环没有包含任何指令。 python希望在那里有一个缩进块,告诉它在循环的每个过程中要做什么。一般情况下,当您可能出现语法错误时,最好在错误消息中报告的行之前查找行上的实际错误。

+0

感谢球员,我非常欣赏的反馈! – Leavingtheecstasy

对于循环的的主体必须缩进。你不能留下空白。因此,def main():成为该机构的第一个语句,这就是解析器标记错误的地方。

现在,请尝试使用虚拟声明:

for counter in range(10): 
    pass 

这是很好的,你删了你的程序,并在同一时间工作的几行。

def FillStudentsNames(): 
 

 
    studentNames = [] 
 
    for studentNames in range(1,11): 
 
     user_input = input("What is the students name? : ") 
 
     print(user_input) 
 

 

 

 

 

 

 

 

 

 

 

 
def FillStudentsGrades(): 
 
     studentGrades =[] 
 
     for studentGrades in range (1,11): 
 
      grade = randint(1,100) 
 
      print(grade) 
 

 
     return studentGrades 
 

 

 

 

 

 
def ShowData(studentNames, studentGrades): 
 
    counter = 0 
 
    studentNames=[] 
 
    studentGrades=[] 
 
    for counter in range(0,10): 
 
     # do something down otherwise main would be assumed to be part of for 
 
     i = 2 
 

 

 

 

 

 
def main(): 
 
    FillStudentsNames = StdNames 
 

 

 

 
main()

见上文的哥们

+0

非常感谢! – Leavingtheecstasy