Write a function findLargestState that figures out which state has the largest population and returns that.
What will be an ideal response?
Note: This answer requires searching through each of the states and checking if its population is greater than the current maximum. Additionally, its necessary to in some way skip the first line, as otherwise parsing a string as an int will lead to an error, and the second line as it’ll get the entire population of the united states.
```
def findLargestState ():
file = open(getMediaPath("state-populations.csv"),"rt")
lines = file.readlines()
file.close()
maxState = "None"
maxPopulation = 0
for index in range(2, len(lines)):
parts = lines[index].split(",")
if parts[5].isdigit():
thisPopulation = int(parts[5])
if thisPopulation>maxPopulation:
maxPopulation = thisPopulation
maxState = parts[4]
return maxState
```
You might also like to view...
Explain the difference between a combo box and a dialog box.
What will be an ideal response?
Which of the symbols below is a scoping operator?
A. : B. * C. -> D. ::
List five best practices a Web system administrators should use to secure a Web server.
What will be an ideal response?
Samba uses the ____ configuration file to provide services.
A. /etc/smb/smb.conf B. /etc/samba/smb.conf C. /etc/xinetd.d/config D. /etc/xinetd.d/smb.conf