简体   繁体   中英

Expected an indent block - python

I'm in my first programming cass and I'm trying to understand Python.

I've gotten an indent block on this code: from random import*

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()

and I' not really sure why. I indented the "def main", because that's where the parser was showing the error. Now I get the same message, but not pointing out a specific space.

The body of a for loop has to be indented. You can't leave it blank. Thus, def main(): becomes the first statement of that body, and that's where the parser flags the error.

For now, try using the dummy statement:

for counter in range(10):
    pass

It's good that you're stubbing out your program, and working a few lines at a time.

you got the error because the for loop right before the def main line contains no instructions. python expects an indented block right there' telling it what to do in each pass of the loop. in general, when you can syntax errors, it's good practice to look for the actual error on the line before the one reported in the error message.

 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() 

See above buddy

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM