Python ';学生';对象没有属性';打印详细信息';
大家好,我的代码有问题,我不太确定哪里出了问题,我真的很感谢大家的帮助Python ';学生';对象没有属性';打印详细信息';,python,Python,大家好,我的代码有问题,我不太确定哪里出了问题,我真的很感谢大家的帮助 class Student: def __init__(self, name, age, course, ID): self.name = name self.age = age self.course = course self.ID = ID def print_details(self): print("Name: " + se
class Student:
def __init__(self, name, age, course, ID):
self.name = name
self.age = age
self.course = course
self.ID = ID
def print_details(self):
print("Name: " + self.name)
print("Age: " + str(self.age))
print("Course: " + self.course)
print("Student ID: " + self.ID)
student1 = Student("Bob", 20, "Computer Science", "1000121")
student2 = Student("Alice", 21, "Computer Science", "1000475")
student3 = Student("Jane", 18, "Information Technology", "1000823")
student1.print_details()
student2.print_details()
student3.print_details()
因此,我得到的错误是,当试图运行代码时
“学生”对象没有“打印详细信息”属性
提前感谢您编写的函数不在学生课堂上,请将其缩进一块
class Student:
def __init__(self, name, age, course, ID):
self.name = name
self.age = age
self.course = course
self.ID = ID
def print_details(self):
print("Name: " + self.name)
print("Age: " + str(self.age))
print("Course: " + self.course)
print("Student ID: " + self.ID)
student1 = Student("Bob", 20, "Computer Science", "1000121")
student2 = Student("Alice", 21, "Computer Science", "1000475")
student3 = Student("Jane", 18, "Information Technology", "1000823")
student1.print_details()
student2.print_details()
student3.print_details()
print\u details()
方法在类之外。常见缩进错误。修复代码中的缩进。该功能应为内部一级。它应该在课堂上@michale谢谢你我对这一切都是新手,还在学习