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
```

Computer Science & Information Technology

You might also like to view...

Develop a pseudocode algorithm for the isEmpty operation assuming that there is not a count variable.

What will be an ideal response?

Computer Science & Information Technology

Describe the properties of a server.

What will be an ideal response?

Computer Science & Information Technology