-2

I'm trying to list the names and positions of teachers and facility at a university. When I try to run the program it does not work and I get an error message that says 'str' object has no attribute 'dean_print'

class TSC:

    def __init__(self, President, Dean1, Dean2, Dean3, Dean4, Dean5, Chair1, Chair2, Chair3, Chair4, Chair5, Chair6, Chair7, Chair8, Chair9, Chair10):
        self.president = President
        self.dean_one = Dean1
        self.dean_two = Dean2
        self.dean_three = Dean3
        self.dean_four = Dean4
        self.dean_five = Dean5
        self.chair_one = Chair1
        self.chair_two = Chair2
        self.chair_three = Chair3
        self.chair_four = Chair4
        self.chair_five = Chair5
        self.chair_six = Chair6
        self.chair_seven = Chair7
        self.chair_eight = Chair8
        self.chair_nine = Chair9
        self.chair_ten = Chair10

    def pres(self):
        print(f"The President of TSC is ", end="")
        print(self.president)
   
    def deans(self):
        print(f"The dean of the school of Arts & Sciences is ", end = "")
        self.dean_one.dean_print()
       
        print(f"The dean of the school of Education is ", end = "")
        print(self.dean_two.dean_print1())
       
        print(f"The dean of the school of Nursing and Wellness is ", end = "")
        print(self.dean_three.dean_print1())
       
        print(f"The dean of the school of Buisness ans Digital Media is ", end = "")
        print(self.dean_four.dean_print1())
       
        print(f"The dean of the school of Wizrady is ", end = "")
        print(self.dean_five.dean_print1())


class Arts_and_Sciences:

    def __init__(self, dean):
        self.dean_one = dean
    def dean_print(self):
        print(f"{self.dean_one}")
   
    def heads_AnS(self):
        print(f"The head of of Art is ", end = "")
        print(self.chair_one.heads1_print())
       
        print(f"The head of Science is ", end = "")
        print(self.chair_two.heads2_print())
   


class Education:

    def __init__(self, dean):
        self.dean_two_b = dean
    def dean_print1(self):
        print(f"{self.dean_two_b}")
    def heads_Edu(self):
        print(f"The head of Education is ", end = "")
        print(self.chair_three.heads3_print())
       
        print(f"The head of Teaching Skills is ", end = "")
        print(self.chair_four.heads4_print())


class Nursing:

    def __init__(self, dean):
        self.dean_one_b = dean
    def dean_print1(self):
        print(f"{self.dean_three_b}")
    def heads_Nrs(self):
        print(f"The head of Nursing is ", end = "")
        print(self.chair_five.heads5_print())
       
        print(f"The head of Wellness is ", end = "")
        print(self.chair_six.heads6_print())

class Business:

    def __init__(self, dean):
        self.dean_one_b = dean
    def dean_print1(self):
        print(f"{self.dean_four_b}")
    def heads_Buss(self):
        print(f"The head of Buisness is ", end = "")
        print(self.chair_seven.heads7_print())
       
        print(f"The head of Digital Media is ", end = "")
        print(self.chair_eight.heads8_print())

class Wizardy:

    def __init__(self, dean):
        self.dean_one_b = dean
    def dean_print1(self):
        print(f"{self.dean_five_b}")
    def heads_Wiz(self):
        print(f"The head of Spells is ", end = "")
        print(self.chair_nine.heads9_print())
       
        print(f"The head of Potions is ", end = "")
        print(self.chair_ten.heads10_print())

class Heads:
    def __init__(self, head1, head2, head3, head4, head5, head6, head7, head8, head9, head10):
        self.head_one = head1
        self.head_two = head2
        self.head_three = head3
        self.head_four = head4
        self.head_five = head5
        self.head_six = head6
        self.head_seven = head7
        self.head_eight = head8
        self.head_nine = head9
        self.head_ten = head10
    def heads1_print(self):
        print(f"{self.head_one}")
    def heads2_print(self):
        print(f"{self.head_two}")
    def heads3_print(self):
        print(f"{self.head_three}")
    def heads4_print(self):
        print(f"{self.head_four}")
    def heads5_print(self):
        print(f"{self.head_five}")
    def heads6_print(self):
        print(f"{self.head_six}")
    def heads7_print(self):
        print(f"{self.head_seven}")
    def heads8_print(self):
        print(f"{self.head_eight}")
    def heads9_print(self):
        print(f"{self.head_nine}")
    def heads10_print(self):
        print(f"{self.head_ten}")


faculity = TSC("Pres Idint", "Scin Ark", "Eden Cathrine", "Nurswell Wells", "Bunson Meda", "Albus Dumbledore", "John Smith", "Paul Adam", "Betsy Zoe", "Simon Peter", "James Maddison", "Page Turner", "Max Scott", "Daniel Goodman", "Harry Potter", "Severus Snape")

faculity.pres()
faculity.deans()

When I ran the code I was expecting it to print out a list of people and their positions at the university. Instead of that happening I keep receiving the error message that I indicated above.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
Martha
  • 1
  • 1
  • 2
    try using data structures (lists and dicts) instead of serially named variables – gog Nov 22 '22 at 22:48
  • 1
    Welcome to Stack Overflow! What do you need help with exactly? The error message seems to say exactly what the problem is. Skimming your code, it looks like `"Scin Ark"` is being passed in as `Dean1`, assigned to `self.dean_one`, then the error happens at `self.dean_one.dean_print()`. Please read [ask]. Either way, this is too much code. If you still need debugging help, make a [mre] including the [full error message with traceback](https://meta.stackoverflow.com/q/359146/4518341) and expected output. – wjandrea Nov 22 '22 at 22:48
  • 1
    You might want to check out [How to step through Python code to help debug issues?](/q/4929251/4518341) and [How to debug small programs](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/) by Eric Lippert – wjandrea Nov 22 '22 at 22:50
  • Something like `faculity = TSC("Pres Idint", Arts_and_Sciences("Scin Ark"), Education("Eden Cathrine"), Business("Nurswell Wells"), "Bunson Meda", "Albus Dumbledore", "John Smith", "Paul Adam", "Betsy Zoe", "Simon Peter", "James Maddison", "Page Turner", "Max Scott", "Daniel Goodman", "Harry Potter", "Severus Snape")` should lead to some progress. – Cristian Ciupitu Nov 22 '22 at 22:55
  • @CristianCiupitu this suggestion was extremely helpful and got me past the sticking point. Thanks very much!! – Martha Nov 23 '22 at 00:24

1 Answers1

0

There are many errors in the code. For example, in your Wizardy class, you have the class method dean_print1 which tries to reference "self.dean_five_b". You have not defined the instance attribute dean_five_b for this class, only dean_one_b. I'm not going to point out all these errors to you as I'm sure you can apply that concept to the rest of those mistakes. However, I recommend reviewing OOP concepts to improve your understanding and implementation of classes. For a relatively close comparison and generalization to what you did above, you can break this problem down to build a better class structure/understanding. Here you have a list of "faculty". Each faculty member has a "job title" and belongs to a "college" within the university (or maybe only a subset belong to a specific college). You can reduce the verbose writing above with a single class "faculty" where each member has attributes name, job_title, and college. From there, you could define a single print statement to display this information: print(f"{self.name} is the {self.job_title} for the college of {self.college}" or similar if you only a subset of faculty belong to a college and you need to make that output conditional. To do this, you will define an instance of your faculty class for each faculty member rather than defining a class with all faculty. You could also use a basic dictionary for this case but I'm assuming this is an attempt to understand classes. If you need methods specific to the job title or college, then you could create a subclass of faculty to store those specific methods. The original example is shown below.

class faculty:

    def __init__(self, name, job_title, college=None):
        self.name = name
        self.job_title = job_title
        self.college = college

    def display_info(self):
        if self.college is not None:
            print(f"{self.name} is the {self.job_title} for the college of {self.college}")
        else:
            print(f"{self.name} is the {self.job_title}")


f1 = faculty("john doe", "Dean", "Education")
f2 = faculty("harry potter", "rebel", "Wizardy")

f1.display_info()
f2.display_info()

There's a lot I'm not covering so review some OOB literature on your own to learn more.