indented error and get_student isnt defined

Viewed 15

Errors i'm getting:

Expected indented block on #def main

get_student is not defined

class Student:

def main(): 
    student = get_student()
    print(f"{student.name} from {student.house}")


def get_student():
    student = Student() 
    student.name = input("name: ")
    student.house = input("house: ")
    return student


if __name__ == "__main__":
    main()
1 Answers

You did not format the code perfectly. Your Student class is empty at the moment. You need to write the class, press a tab, write the function, press tab, etc. Try this:

class Student:
    def get_student():
        student = Student()
        student.name = input("name: ")
        student.house = input("house: ")
        return student



def main(): 
    student = Student.get_student()
    print(f"{student.name} from {student.house}")
    
main()

Just make sure you're using tabs everywhere instead of spaces when you run the code.

Related