uestion) class Player: total_player = 0 def __init__(self,name,country): self.name = name self.country = country def __str__(self):
Design TennisPlayer class which inherit from Player class so that the
following code provides the expected output.
[addGrandSlams() method should work any number of parameters assuming that
the parameter number will be an even number and greater than 1]
(python question)
class Player:
total_player = 0
def __init__(self,name,country):
self.name = name
self.country = country
def __str__(self):
return 'Name: '+self.name+'\nCountry Name: '+str(self.country)
# Write your codes here.
# Do not change the following lines of code. Order of the year in printing
grand slams doesn’t matter.
p1 = TennisPlayer("Novac Djokovic", 'Serbia')
print("==============================")
p1.addGrandSlams('Wimbledon',2021, 'French Open',2021,'Australian
Open',2020)
print("==============================")
print(p1)
print("==============================")
p2 = TennisPlayer("Roger Federer", 'Switzerland')
print("==============================")
p2.addGrandSlams('Wimbledon',2017, 'US Open',2008,'Australian
Open',2017,'Australian Open',2018)
print("==============================")
print(p2)
print("==============================")
print('Total Players: ', Player.total_player)
OUTPUT:
New Tennis Player Added - Novac Djokovic from Serbia
==============================
==============================
Name: Novac Djokovic
Country Name: Serbia
Grand Slams:
2021: ['Wimbledon','French Open']
2020: ['Australian Open']
==============================
New Tennis Player Added - Roger Federer from Switzerland
==============================
==============================
Name: Roger Federer
Country Name: Switzerland
Grand Slams:
2018: ['Australian Open']
2017: ['Wimbledon','Australian Open']
2008: ['US Open']
==============================
Total Players: 2
Step by step
Solved in 2 steps