[英]AttributeError: 'str' object has no attribute 'shape' error
[英]AttributeError: 'str' object has no attribute 'member' Error
我正在嘗試為我的編碼 class 制作 GPA 計算器。 我一直遇到這個錯誤,我希望你能解決它。
class Student:
role = 'learn'
def __init__(self,name,grade,fav_color,school,GPA):
self.name = name
self.grade = grade
self.fav_color = fav_color
self.school = school
self.GPA = GPA
class School:
roster = []
def __init__(self, school_name):
self.school_name = school_name
def add_members(self):
name = input('What is their name')
is_student = input('Are they a student? (y/n) ')
if is_student == 'y':
grade = input('What grade are they in?')
school = input('What school do they go to?')
mathGPA = int(input('How much GPA does the student have for math? '))
sciGPA = int(input('How much GPA does the student have for science? '))
socialGPA = int(input('How much GPA does the student have for social? '))
laGPA = int(input('How much GPA does the student have for LA? '))
addedGPA = int(mathGPA + sciGPA + socialGPA + laGPA)
print(addedGPA)
calculatedGPA = (addedGPA / 4)
new_member = Student(name, grade, 'red', school, calculatedGPA)
else:
subject = input('What do they teach? ')
school = input('What school do they go to?')
new_member = Teacher(name, subject, school)
self.roster.append(new_member)
if input('Add another member (y/n) ') == 'y':
self.add_members()
def show_roster(self):
for member in self.roster:
if isinstance(member, Teacher):
print('{} is a teacher, they teach {} at {}'.format(member.name, member.subject, member.school))
elif isinstance(member, Student):
print('{} is a student, they are in grade {} at this school called {}. Their GPA is {}'.format(member.name, member.grade, member.school. member.GPA))
錯誤:
Traceback (most recent call last):
File "C:\Users\kp876\Desktop\Python\Python projects\1 26 2021 lesson 3.py", line 64, in <module>
my_school.show_roster()
File "C:\Users\kp876\Desktop\Python\Python projects\1 26 2021 lesson 3.py", line 57, in show_roster
print('{} is a student, they are in grade {} at this school called {}. Their GPA is {}'.format(member.name, member.grade, member.school. member.GPA))
AttributeError: 'str' object has no attribute 'member'
我試圖讓它說出他們的平均 GPA 是多少,但錯誤一直在妨礙我。 我不知道如何解決它,我希望你能!
print('{} is a student, they are in grade {} at this school called {}. Their GPA is {}'.format(member.name, member.grade, member.school. member.GPA))
我做了一個。 而不是a,在member.GPA
的前面
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.