0
Someone please help me write oop in python my topic is football management system
6 Antworten
+ 1
What help do you need?
Show your code so we can check on it. Describe what it is supposed to do and which issue you are facing.
+ 3
Please link your code instead of pasting it into the comments: It is difficult to read, cannot be tested and likely has indentation errors.
Click on the little +, Insert Code, sort for My Code Bits, select your code.
+ 2
class FootballTeamManagementSystem:
def __init__(self, team_name, coach_name):
self.team_name = team_name
self.coach_name = coach_name
self.players_stack = []
class Player:
def __init__(self, player_name, position, jersey_number, age, nationality, height, weight, is_injured=False):
self.player_name = player_name
self.position = position
self.jersey_number = jersey_number
self.age = age
self.nationality = nationality
self.height = height
self.weight = weight
self.is_injured = is_injured
def add_player(self, player_name, position, jersey_number, age, nationality, height, weight, is_injured=False):
player = self.Player(player_name, position, jersey_number, age, nationality, height, weight, is_injured)
self.players_stack.append(player)
return f"Player {player_name} added to {self.team_name}.
+ 2
Bm scout ,
A couple suggestions:
1. Shrink your names. Imagine if every cold and hot water faucet were labeled "cold_water_faucet" and "hot_water_faucet" instead of "cold" and "hot". Imagine if all labels were like that. "Half_gallon_cow_milk_carton", etc. How much more cluttered would our world be? You're doing a lot of that.
FootballTeamManagementSystem should be Team.
team_name should be team.
coach_name should be coach.
players_stack should be players.
etc. Keep shrinking throughout.
2. Even though "age" is a variable used in many examples by Sololearn and other educational sites, it's a terrible idea for real-world databases, because it's static and becomes incorrect as time passes. What you need to store is dob (date of birth). Then, if you need to, you can make a managed attribute (a property) called age that stores nothing but calculates and returns the current age whenever it is retrieved, based on the dob and today's date (which you get access to by importing datetime).
+ 1
def display_team_info(self):
print(f"\n{self.team_name} - Managed by Coach {self.coach_name}")
print("Players:")
for player in reversed(self.players_stack):
status = "Injured" if player.is_injured else "Available"
print(f"Jersey #{player.jersey_number} - {player.player_name} ({player.position}), Age: {player.age}, Nationality: {player.nationality}, Height: {player.height}, Weight: {player.weight}, Status: {status}")
def get_player_details(self, jersey_number):
for player in self.players_stack:
if player.jersey_number == jersey_number:
return f"\nPlayer Details - {player.player_name} ({player.position}): Age: {player.age}, Nationality: {player.nationality}, Height: {player.height}, Weight: {player.weight}, Status: {'Injured' if player.is_injured else 'Available'}"
return f"\nPlayer with Jersey #{jersey_number} not found in {self.team_name}."