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.
>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.')