Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I can’t understand why the ‘team’ term keeps coming up undefined?

While trying to complete an assignment, my result keeps coming up as partially correct in the ZyBooks system. I’ve tried everything I can possibly think of to solve the issue, and have no idea what else to try. Here are the instructions for the assignment:

class Team:
    def __init__(self):
        self.name = 'team'
        self.wins = 0
        self.losses = 0

    # TODO: Define get_win_percentage()
    def get_win_percentage(self):
        return team.wins / (team.wins + team.losses)
    # TODO: Define print_standing()
    def print_standing(self):
        print(f'Win percentage: {team.get_win_percentage():.2f}')
        if team.get_win_percentage() >= 0.5:
            print('Congratulations, Team', team.name,'has a winning average!')
        else:
            print('Team', team.name, 'has a losing average.')
  

if __name__ == "__main__":
    team = Team()
    user_name = input()
    user_wins = int(input())
    user_losses = int(input())
    
    team.name = user_name
    team.wins = user_wins
    team.losses = user_losses
    
    team.print_standing()

I’m passing all the auto-generated tests aside from the last three, and I can’t understand why? To Do’s have to be included as well.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

As noted in comments, in the below you’ve used team rather than self.

   # TODO: Define get_win_percentage()
   def get_win_percentage(self):
       return team.wins / (team.wins + team.losses)
   # TODO: Define print_standing()
   def print_standing(self):
       print(f'Win percentage: {team.get_win_percentage():.2f}')
       if team.get_win_percentage() >= 0.5:
           print('Congratulations, Team', team.name,'has a winning average!')
       else:
           print('Team', team.name, 'has a losing average.')

Corrected:

    # TODO: Define get_win_percentage()
    def get_win_percentage(self):
        return self.wins / (self.wins + self.losses)
    # TODO: Define print_standing()
    def print_standing(self):
        print(f'Win percentage: {self.get_win_percentage():.2f}')
        if self.get_win_percentage() >= 0.5:
            print('Congratulations, Team', self.name, 'has a winning average!')
        else:
            print('Team', self.name, 'has a losing average.')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading