结果未显示在同伴辅导模拟程序中

发布于 2025-01-14 11:39:39 字数 6243 浏览 3 评论 0原文

所以这是代码:

class Tutor:

  def __init__(self, name, grade, subjects, days, hours = 0.0):
      self.name = name
      self.grade = grade
      self.subjects = subjects
      self.days = days
      self.hours = 0.0

  def get_name(self):
    return self.name
    
  def get_grade(self):
    return self.grade
  
  def get_subjects(self):
    return self.subjects
  
  def get_days(self):
    return self.days
  
  def get_hours(self):
    return self.hours
  
  def add_hours(self, hours = 0.0):
    self.hours += hours
  
  def __str__(self):
    return f"""{self.name}
    Grade: {self.grade}
    Subjects: {self.subjects}
    Days: {self.days}
    Hours: {self.hours}"""
    return string

class Peer_tutoring:
    """A class to represent and manage NNHS peer tutors"""
    def __init__(self, tuts = None):
        if tuts == None:
            tuts = []
        # a list of Tutor objects, representing all the active peer tutors
        self.tutors = tuts
        self.teacher = "Mrs. Moore"
    
    def add_tutor(self, new_tutor):
        """adds a new Tutor object to the tutor list
        param: new_tutor - a Tutor object"""
        self.tutors.append(new_tutor)

    def remove_tutor(self, tutor):
        """removes a tutor from the tutor list, by name
        param: tutor - a String name of a Tutor"""
        for tut in self.tutors:
            if tut.get_name() == tutor:
                i = self.tutors.index(tut)
                return self.tutors.pop(i)
    
    def find_tutor_subj(self, subj):
        """returns a list of all tutors that tutor in a certain subject
        param: subj - a String subject to search for"""
        tuts = []
        for tut in self.tutors:
            subs = tut.get_subjects()
            if subj in subs:
                    tuts.append(tut)
        return tuts
    
    def find_tutor_day(self, day):
        """returns a list of all tutors that tutor a certain day
        param: day - a String day to search for"""
        tuts = []
        for tut in self.tutors:
            d = tut.get_days()
            if day in d:
                tuts.append(tut)
        return tuts

    def add_hours(self, name, hours):
        """Adds hours to a Tutor object.
        param: name - a String name of a tutor
        param: hours - an int or float number of hours to add"""
        for i in range(len(self.tutors)):
            if self.tutors[i].get_name() == name:
                self.tutors[i].add_hours(hours)

    def display_tutors(self):
        """prints all Tutors in the tutor list"""
        for t in self.tutors:
            print(t)
    
    def __str__(self):
        """Displays information about NNHS Peer Tutoring, including the teacher, number of tutors, and total hours of tutoring"""
        hours = 0
        for t in self.tutors:
            hours += t.get_hours()
        string = "\nNNHS Peer Tutoring" + "\nTeacher: " + self.teacher + "\nNumber of active tutors: " + str(len(self.tutors))
        string += "\nTotal hours tutored: " + str(hours)
        return string
# main function for the Peer Tutoring App
#   Complete the implementation of this function so the app works as intended.
from peer_tutoring import *
from tutor import *

def main():
  menu = """
        1. Display all tutors
        2. Find a tutor (by subject)
        3. Find a tutor (by day)
        4. Add a tutor
        5. Remove a tutor (by name)
        6. Add tutoring hours
        7. NNHS Tutoring Stats
        0. Exit
    """
  tutor1 = Tutor("Lisa Simpson", 11, ["Band", "Mathematics", "Biology"], ["Monday", "Wednesday"])
  tutor2 = Tutor("Spongebob Squarepants", 9, ["Social Studies", "Art"], ["Wednesday"])
  tutor3 = Tutor("Bender", 12, ["Computer Science", "Mathematics", "Statistics"], ["Wednesday", "Friday"])
  tutor4 = Tutor("April O'Neil", 10, ["Social Studies", "History", "English"], ["Tuesday", "Thursday"])
  tutor5 = Tutor("Mickey Mouse", 9, ["Art", "Science"], ["Monday", "Tuesday"])
  tutor6 = Tutor("Black Panther", 10, ["Mathematics", "Science"], ["Tuesday", "Friday"])
  tutor7 = Tutor("Princess Peach", 12, ["Culinary", "History"], ["Thursday", "Friday"])
  pt = Peer_tutoring("")
    # initialize Peer_tutoring object with initial list of tutors
  nnhs_tutors = Peer_tutoring([tutor1, tutor2, tutor3, tutor4, tutor5, tutor6, tutor7])

    # run the app
  print("\nWelcome to the NNHS Peer Tutoring App!\n")
  choice = "1"
  addsub = []
  newsub = ""
  newgrade = 10
  while choice != "0":
    print(menu)
    choice = input("\nSelect an option: ")
    subjec = ""
    if choice == "1":
      nnhs_tutors.display_tutors()
    elif choice == "2":
      subjec = input("What is the name of the subject you'd like to see available tutors for? ")
      nnhs_tutors.find_tutor_subj(subjec)
    elif choice == "3":
      days = input("What is the day you'd like to see available tutors for? ")
      nnhs_tutors.find_tutor_day(days)
    elif choice == "4":
      newname = input("What is the name of the new tutor? ")
      if newgrade > 8 and newgrade < 13:
        newgrade = input("What is the grade of the new tutor (9-12) ? ")
      elif newgrade <= 8 and newgrade >= 13:
        print("Please enter a number between 9 and 12.")
      while newsub != "":
        newsub = input("Subject to add? (Leaven empty if done) ")
        addsub.append(newsub)
      nnhs_tutors.add_tutor(addsub)
    elif choice == "5":
      removed = input("Which tutor would you like to remove? ")
      nnhs_tutors.remove_tutor(removed)
    elif choice == "6":
      addername = input("Name of tutor to add hours to? ")
      adderhour = input("Numbers of hours to add? ")
      nnhs_tutors.add_hours(addername, adderhour)
    elif choice == "7":
      print(nnhs_tutors)
    elif choice == "0":
      print("\nThanks for using the NNHS Peer Tutoring App!")

if __name__ == "__main__":
    main()

那么,这是我需要帮助解决的问题。

如果我输入 2,它应该询问我您要搜索的主题是什么。一旦我输入所选主题,它应该显示匹配的学生。 (没有收到错误,但由于某些原因不会显示)

如果我输入3,它应该按天搜索(从周一到周五)并列出匹配日期的学生。 (与2同样的问题,没有弹出错误但不会显示)

如果我输入4,它应该通过输入他们的姓名、年级和科目来添加导师。 (输入姓名和成绩后,主题条目将不会显示,他们只是跳过它。并且 nnhs_tutors 中没有显示任何新内容)

还存在其他问题,但我稍后会解决这个问题。

有人会提供一些说明吗?

so here's the code:

class Tutor:

  def __init__(self, name, grade, subjects, days, hours = 0.0):
      self.name = name
      self.grade = grade
      self.subjects = subjects
      self.days = days
      self.hours = 0.0

  def get_name(self):
    return self.name
    
  def get_grade(self):
    return self.grade
  
  def get_subjects(self):
    return self.subjects
  
  def get_days(self):
    return self.days
  
  def get_hours(self):
    return self.hours
  
  def add_hours(self, hours = 0.0):
    self.hours += hours
  
  def __str__(self):
    return f"""{self.name}
    Grade: {self.grade}
    Subjects: {self.subjects}
    Days: {self.days}
    Hours: {self.hours}"""
    return string

class Peer_tutoring:
    """A class to represent and manage NNHS peer tutors"""
    def __init__(self, tuts = None):
        if tuts == None:
            tuts = []
        # a list of Tutor objects, representing all the active peer tutors
        self.tutors = tuts
        self.teacher = "Mrs. Moore"
    
    def add_tutor(self, new_tutor):
        """adds a new Tutor object to the tutor list
        param: new_tutor - a Tutor object"""
        self.tutors.append(new_tutor)

    def remove_tutor(self, tutor):
        """removes a tutor from the tutor list, by name
        param: tutor - a String name of a Tutor"""
        for tut in self.tutors:
            if tut.get_name() == tutor:
                i = self.tutors.index(tut)
                return self.tutors.pop(i)
    
    def find_tutor_subj(self, subj):
        """returns a list of all tutors that tutor in a certain subject
        param: subj - a String subject to search for"""
        tuts = []
        for tut in self.tutors:
            subs = tut.get_subjects()
            if subj in subs:
                    tuts.append(tut)
        return tuts
    
    def find_tutor_day(self, day):
        """returns a list of all tutors that tutor a certain day
        param: day - a String day to search for"""
        tuts = []
        for tut in self.tutors:
            d = tut.get_days()
            if day in d:
                tuts.append(tut)
        return tuts

    def add_hours(self, name, hours):
        """Adds hours to a Tutor object.
        param: name - a String name of a tutor
        param: hours - an int or float number of hours to add"""
        for i in range(len(self.tutors)):
            if self.tutors[i].get_name() == name:
                self.tutors[i].add_hours(hours)

    def display_tutors(self):
        """prints all Tutors in the tutor list"""
        for t in self.tutors:
            print(t)
    
    def __str__(self):
        """Displays information about NNHS Peer Tutoring, including the teacher, number of tutors, and total hours of tutoring"""
        hours = 0
        for t in self.tutors:
            hours += t.get_hours()
        string = "\nNNHS Peer Tutoring" + "\nTeacher: " + self.teacher + "\nNumber of active tutors: " + str(len(self.tutors))
        string += "\nTotal hours tutored: " + str(hours)
        return string
# main function for the Peer Tutoring App
#   Complete the implementation of this function so the app works as intended.
from peer_tutoring import *
from tutor import *

def main():
  menu = """
        1. Display all tutors
        2. Find a tutor (by subject)
        3. Find a tutor (by day)
        4. Add a tutor
        5. Remove a tutor (by name)
        6. Add tutoring hours
        7. NNHS Tutoring Stats
        0. Exit
    """
  tutor1 = Tutor("Lisa Simpson", 11, ["Band", "Mathematics", "Biology"], ["Monday", "Wednesday"])
  tutor2 = Tutor("Spongebob Squarepants", 9, ["Social Studies", "Art"], ["Wednesday"])
  tutor3 = Tutor("Bender", 12, ["Computer Science", "Mathematics", "Statistics"], ["Wednesday", "Friday"])
  tutor4 = Tutor("April O'Neil", 10, ["Social Studies", "History", "English"], ["Tuesday", "Thursday"])
  tutor5 = Tutor("Mickey Mouse", 9, ["Art", "Science"], ["Monday", "Tuesday"])
  tutor6 = Tutor("Black Panther", 10, ["Mathematics", "Science"], ["Tuesday", "Friday"])
  tutor7 = Tutor("Princess Peach", 12, ["Culinary", "History"], ["Thursday", "Friday"])
  pt = Peer_tutoring("")
    # initialize Peer_tutoring object with initial list of tutors
  nnhs_tutors = Peer_tutoring([tutor1, tutor2, tutor3, tutor4, tutor5, tutor6, tutor7])

    # run the app
  print("\nWelcome to the NNHS Peer Tutoring App!\n")
  choice = "1"
  addsub = []
  newsub = ""
  newgrade = 10
  while choice != "0":
    print(menu)
    choice = input("\nSelect an option: ")
    subjec = ""
    if choice == "1":
      nnhs_tutors.display_tutors()
    elif choice == "2":
      subjec = input("What is the name of the subject you'd like to see available tutors for? ")
      nnhs_tutors.find_tutor_subj(subjec)
    elif choice == "3":
      days = input("What is the day you'd like to see available tutors for? ")
      nnhs_tutors.find_tutor_day(days)
    elif choice == "4":
      newname = input("What is the name of the new tutor? ")
      if newgrade > 8 and newgrade < 13:
        newgrade = input("What is the grade of the new tutor (9-12) ? ")
      elif newgrade <= 8 and newgrade >= 13:
        print("Please enter a number between 9 and 12.")
      while newsub != "":
        newsub = input("Subject to add? (Leaven empty if done) ")
        addsub.append(newsub)
      nnhs_tutors.add_tutor(addsub)
    elif choice == "5":
      removed = input("Which tutor would you like to remove? ")
      nnhs_tutors.remove_tutor(removed)
    elif choice == "6":
      addername = input("Name of tutor to add hours to? ")
      adderhour = input("Numbers of hours to add? ")
      nnhs_tutors.add_hours(addername, adderhour)
    elif choice == "7":
      print(nnhs_tutors)
    elif choice == "0":
      print("\nThanks for using the NNHS Peer Tutoring App!")

if __name__ == "__main__":
    main()

So, here's the problems I need help solving with.

If I enter 2, it should ask me what's the subject you'd like to search. And once I enter the selected subject it should display the matching students. (Doesn't receives an error but won't display for some reasons)

If I enter 3, it should search by day (from Monday to Friday) and list out the students with matched day/days. (Same problem with 2, no errors popping up but won't display)

If I enter 4, it should add a tutor by entering their name, grade and subject. (Once name and grade was entered the subject entry won't show up, they just skipped it. And nothing new displays in nnhs_tutors)

There are other problems that exists, but I'll work on that later.

Would anyone provide some instructions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文