Question

In: Computer Science

Python Please Define a class that will represent soccer players as objects. A soccer player will...

Python Please

Define a class that will represent soccer players as objects. A soccer player will have as attributes, name, age, gender, team name, play position on the field, total career goals scored. The class should have the following methods:

1. initializer method that will values of data attributes arguments. Use 0 as default for career goals scored.

2. str method to return all data attributes as combined string object.

3. addToGoals that will accept an argument of int and add to the career goals scored.

4. provide mutators for age, play position on the field, and team name.

5. provide an accessor that will return all data attributes as a tuple.

Solutions

Expert Solution

Program

Text Format:

class SoccerPlayer:
    def __init__(self, name, age, gender, team_name, position, goals=0):
        # Constructor to initialize data attributes
        self.name = name
        self.age = age
        self.gender = gender
        self.team_name = team_name
        self.play_position = position
        self.career_goals = goals

    def __str__(self):
        # return all data attributes as combined string object.
        return 'Name:' + self.name + ', age:' + str(self.age) + ', gender:' + self.gender + \
               ', team name:' + self.team_name + ', play position:' + self.play_position + \
               ', career goals:' + str(self.career_goals)

    def addToGoals(self, goals):
        # add to the career goals scored.
        self.career_goals += goals

    def set_age(self, age):
        # mutator for age
        self.age = age

    def set_play_position(self, position):
        # mutator for play_position
        self.play_position = position

    def set_team_name(self, team):
        # mutator for team_name
        self.team_name = team

    def __iter__(self):
        # accessor return all data attributes as a tuple
        yield from self.name, self.age, self.gender, self.team_name, self.play_position, self.career_goals


p = SoccerPlayer('John', 23, 'male', 'AC Milan', 'Forward', 34)
name, age, gender, team, position, goals = p
p.addToGoals(3)
print(p)
print(tuple(p))

Output:

Name:John, age:23, gender:male, team name:AC Milan, play position:Forward, career goals:37
('John', 23, 'male', 'AC Milan', 'Forward', 37)

Solving your question and helping you to well understand it is my focus. So if you face any difficulties regarding this please let me know through the comments. I will try my best to assist you. However if you are satisfied with the answer please don't forget to give your feedback. Your feedback is very precious to us, so don't give negative feedback without showing proper reason.
Always avoid copying from existing answers to avoid plagiarism.
Thank you.


Related Solutions

python Design a class named IP_address to represent IP address objects. The IP_addressclass contains the following...
python Design a class named IP_address to represent IP address objects. The IP_addressclass contains the following A number of instance variables/fields to store a table of data. You can design them by your own. A constructor that creates a table with the following: a list of data. ip address a integer to indicate the number of elements in the sum_list/freq_list/average_list A get_ip_address() method that returns the ip address For example, consider the following code fragment: ip_key = '192.168.0.24' data_list =[(0,...
Python Design a class named IP_address to represent IP address objects. The IP_addressclass contains the following...
Python Design a class named IP_address to represent IP address objects. The IP_addressclass contains the following A number of instance variables/fields to store a table of data. You can design them on your own. A constructor that creates a table with the following: a list of data. IP address an integer to indicate the number of elements in the sum_list/freq_list/average_list A get_ip_address() method that returns the IP address For example, consider the following code fragment: ip_key = '192.168.0.24' data_list =[(0,...
Python Design a class named IP_address to represent IP address objects. The IP_addressclass contains the following...
Python Design a class named IP_address to represent IP address objects. The IP_addressclass contains the following A number of instance variables/fields to store a table of data. You can design them on your own. A constructor that creates a table with the following: a list of data. IP address an integer to indicate the number of elements in the sum_list/freq_list/average_list A get_ip_address() method that returns the IP address For example, consider the following code fragment: ip_key = '192.168.0.24' data_list =[(0,...
Python Please (The Fan class) Design a class named Fan to represent a fan. The class...
Python Please (The Fan class) Design a class named Fan to represent a fan. The class contains: ■ Three constants named SLOW, MEDIUM, and FAST with the values 1, 2, and 3 to denote the fan speed. ■ A private int data field named speed that specifies the speed of the fan. ■ A private bool data field named on that specifies whether the fan is on (the default is False). ■ A private float data field named radius that...
1. Define a struct for a soccer player that stores their name, jersey number, and total...
1. Define a struct for a soccer player that stores their name, jersey number, and total points scored. 2. Using the struct in #1, write a function that takes an array of soccer players and its size as arguments and returns the average number of points scored by the players. 3. Using the struct in #1, write a function that takes an array of soccer players and its size as arguments and returns the index of the player who scored...
In python please Problem Create two server objects using the class create a function, biggest_server_object_sum, outside...
In python please Problem Create two server objects using the class create a function, biggest_server_object_sum, outside of the ServerClass class, that: 1. Takes the IP 2. Sums the octets of the IP together (example 127.0.0.1 = 127+0+0+1 = 128) 3. Returns the Server object with the larger sum Example: server_one = ServerClass("127.0.0.1") server_two = ServerClass("192.168.0.1") result = biggest_ip_sum(server_one, server_two) print(result) Hint Modify get_server_ip in the previous problem. -------------------- Please use this code to start class ServerClass: """ Server class for...
Inventory Purchases Sunflower Soccer Club is a soccer club for dedicated youth soccer players. Use the...
Inventory Purchases Sunflower Soccer Club is a soccer club for dedicated youth soccer players. Use the following information and the t-accounts provided to record the club’s April purchase transactions, assuming it uses the perpetual inventory system. Sunflower purchased 420 engraved medals on account from Evans Engraving for $3.40 each on April 8. The terms of the purchase were 4/10, n/30. The medals were for the winners of a soccer tournament the following weekend. When Sunflower received the medals on April...
Using Python to play Checkers: 1) Create classes to represent the necessary objects for game play....
Using Python to play Checkers: 1) Create classes to represent the necessary objects for game play. This will include, at least, the game board, the two types of pieces and the two sides. You will need to determine the best way to represent the relationship between them. 2) Set up one side of the board. Print the status of the board.
Python Create a move function that is only defined in the base class called Objects. The...
Python Create a move function that is only defined in the base class called Objects. The move function will take two parameters x,y and will also return the updated x,y parameters.
Make a class whose objects each represent a battery. The only attribute an object will have...
Make a class whose objects each represent a battery. The only attribute an object will have is the battery type (one letter). Also, the class has to include the following services for its objects: -determine if two batteries are equal -change battery type -get battery type display battery information the program must include: 1.All / Part 2.Overloading of operators 3.Builder 4.Copy constructor 5.Destroyer 6.Dynamic memory C++
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT