Question: Problem 1 Read the states into a List by calling the readStateData() function and assign the resulting list returned from the function to a variable

Problem 1

Read the states into a List by calling the readStateData() function and assign the resulting list returned from the function to a variable [Provided]. Pass the list to a function named reversePrint(). The function should print the abbreviation followed by a space and then the state name to the output in reverse order, one state per line. Also, with each state, first print the state number counting down from 50 to one (1). Use a FOR loop that reads through the list from the end to the beginning. Use an appropriate range() to control the FOR loop. Remember lists are zero based.

Add your code using the appropriate Problem # # function below. # # DO NOT define any functions INSIDE another function. # #--------------------------------------------------------- # IGNORE and DO NOT change the following three functions. #--------------------------------------------------------- import random

# Return a List of states and abbreviations # ['Alabama', 'AL', 'Alaska', 'AK',....] def readStateData(): with open('states.txt') as f: return [_[:-1] for _ in f]

# Return a List of countries with medals earned # [['United States','46','37','38','121'],['Britain','27','23','17','67'], # ['China','26','18','26','70'], and so on.... ] # # Note: Each list element is a list of five items: # [Country, Gold, Silver, Bronze, Total] def readMedalData(): with open('medals.txt') as f: return [_[:-1].split(',') for _ in f]

# Return a List of 100 random numbers in the # range of 1000..9999 def createRandomList(): def getList(a,b,c): return [random.randint(b,c) for _ in range(a)] return getList(100,1000,9999)

#======================================================== # VVVVVVV Student Solution code below VVVVVVV #========================================================

# Code for Problem 1 def problem01(): stateData = readStateData() print("1. Add your code below. (delete this print)")

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!