Take the first letter of your last name and find a professional sports team (it
ID: 3800147 • Letter: T
Question
Take the first letter of your last name and find a professional sports team (it can be any sport, any country, any league) whose team (or location) begins with that letter. In your program comments, be sure to give the name of the team (and any interesting or informative information about the team that you'd like to share). Then, get the team's roster (it should be available on the team's web page) Write a Python program that uses a list to store only the last names of each player. You can enter the names interactively (but that sounds like a lot of work) or just hard-code the names into your program so that the list contents is initialized at the same time it's declared (similar to the bottom of p. 316) Then, do the following: (1) Output the contents of the list, but use the vertical bar (I) to separate the player names (the chapter has an example of this)Explanation / Answer
Here is the code for you:
#!/usr/bin/python
PlayerLastNames= ['Virat Kohli', 'Ajinkya Rahane', 'Shikar Dhawan', 'Faiz Fazal', 'Gautam Gambhir', 'K. L. Rahul', 'Murali Vijay'];
#Output the contents of the list, separated by |.
for name in PlayerLastNames:
print name, '|',
print
#Append a new player named 'Zygote' to the list.
PlayerLastNames.append('Zygote')
#Output the list to show that it worked.
for name in PlayerLastNames:
print name, '|',
print
#Sort the list so that its in reverse alphabetical order.
list.sort(PlayerLastNames, reverse=True)
#Output the list to show that it worked.
for name in PlayerLastNames:
print name, '|',
print
#Remove the team member at position [3].
PlayerLastNames.remove(PlayerLastNames[2])
#Output the list to show that it worked.
for name in PlayerLastNames:
print name, '|',
print
shortestNameLength = len(PlayerLastNames[0])
longestNameLength = len(PlayerLastNames[0])
for name in PlayerLastNames:
if len(name) < shortestNameLength:
shortestNameLength = len(name)
if len(name) > longestNameLength:
longestNameLength = len(name)
#Output just the shortest name.
print
for name in PlayerLastNames:
if len(name) == shortestNameLength:
print name, '|'
print
#Output just the longest name.
for name in PlayerLastNames:
if len(name) == longestNameLength:
print name, '|'
print
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.