Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

i need help with pylint test should be a 10/10 test import os import sys import matplotlib.pyplot as plt from PIL import Image # Create

i need help with pylint test should be a 10/10 test
image text in transcribed
import os
import sys
import matplotlib.pyplot as plt
from PIL import Image
# Create a states list storing state, capital, population and state flower
states =[]
states.append ( ['Alabama', 'Montgomery', 4918689, 'Camellia'] )
states.append ( ['Alaska', 'Juneau', 727951, 'Forget Me Not'] )
states.append ( ['Arizona', 'Phoenix', 7399410, 'Saguaro Cactus Blossom'] )
states.append ( ['Arkansas', 'Little Rock', 3025875, 'Apple Blossom'] )
states.append ( ['California', 'Sacramento', 39562858, 'Golden Poppy'] )
states.append ( ['Colorado', 'Denver', 5826185, 'White and Lavender Columbine'] )
states.append ( ['Connecticut', 'Hartford', 3559054, 'Mountain Laurel'] )
states.append ( ['Delaware', 'Dover', 982049, 'Peach Blossom'] )
states.append ( ['Florida', 'Tallahassee', 21711157, 'Orange Blossom'] )
states.append ( ['Georgia', 'Atlanta', 10723715, 'Cherokee Rose '] )
states.append ( ['Hawaii', 'Honolulu', 1411151, 'Hibiscus'] )
states.append ( ['Idaho', 'Boise', 1823594, 'Syringa'] )
states.append ( ['Illinois', 'Springfield', 12620571, 'Purple Violet'] )
states.append ( ['Indiana', 'Indianapolis', 6768941, 'Peony'] )
states.append ( ['Iowa', 'Des Moines', 3161522, 'Wild Prairie Rose'] )
states.append ( ['Kansas', 'Topeka', 2915269, 'Sunflower'] )
states.append ( ['Kentucky', 'Frankfort', 4474193, 'Goldenrod'] )
states.append ( ['Louisiana', 'Baton Rouge', 4637898, 'Magnolia'] )
states.append ( ['Maine', 'Augusta', 1349367, 'White Pine Cone and Tassel'] )
states.append ( ['Maryland', 'Annapolis', 6055558, 'Black-Eyed Susan'] )
states.append ( ['Massachusetts', 'Boston', 6902371, 'Mayflower'] )
states.append ( ['Michigan', 'Lansing', 9989642, 'Apple Blossom'] )
states.append ( ['Minnesota', 'St.Paul', 5673015, 'Pink and White Lady Slipper'] )
states.append ( ['Mississippi', 'Jackson', 2971278, 'Magnolia'] )
states.append ( ['Missouri', 'Jefferson City', 6153233, 'White Hawthorn Blossom'] )
states.append ( ['Montana', 'Helena', 1076891, 'Bitterroot'] )
states.append ( ['Nebraska', 'Lincoln', 1943202, 'Goldenrod'] )
states.append ( ['Nevada', 'Carson City', 3132971, 'Sagebrush'] )
states.append ( ['New Hampshire', 'Concord', 1365957, 'Purple Lilac'] )
states.append ( ['New Jersey', 'Trenton', 8878355, 'Violet'] )
states.append ( ['New Mexico', 'Santa Fe', 2100917, 'Yucca Flower'] )
states.append ( ['New York', 'Albany', 19376771, 'Rose'] )
states.append ( ['North Carolina', 'Raleigh', 10594553, 'Dogwood'] )
states.append ( ['North Dakota', 'Bismark', 766044, 'Wild Prairie Rose'] )
states.append ( ['Ohio', 'Columbus', 11701859, 'Scarlet Carnation'] )
states.append ( ['Oklahoma', 'Oklahoma City', 3973707, 'Oklahoma Rose'] )
states.append ( ['Oregon', 'Salem', 4253588, 'Oregon Grape'] )
states.append ( ['Pennsylvania', 'Harrisburg', 12803056, 'Mountain Laurel'] )
states.append ( ['Rhode Island', 'Providence', 1060435, 'Violet '] )
states.append ( ['South Carolina', 'Columbia', 5213272, 'Yellow Jessamine'] )
states.append ( ['South Dakota', 'Pierre', 890620, 'Pasque Flower'] )
states.append ( ['Tennessee', 'Nashville', 6886717, 'Iris'] )
states.append ( ['Texas', 'Austin', 29363096, 'Bluebonnet'] )
states.append ( ['Utah', 'Salt Lake City', 3258366, 'Sego Lily'] )
states.append ( ['Vermont', 'Montpelier', 623620, 'Red Clover'] )
states.append ( ['Virginia', 'Richmond', 8569752, 'Dogwood'] )
states.append ( ['Washington', 'Olympia', 7705917, 'Pink Rhododendron'] )
states.append ( ['West Virginia', 'Charleston', 1780003, 'Rhododendron'] )
states.append ( ['Wisconsin', 'Madison', 5837462, 'Wood Violet'] )
states.append ( ['Wyoming', 'Cheyenne', 579917, 'Indian Paintbrush'] )
states.sort()
# Function to sort the tuple variable based on key
def sort_tuple(tup, key, rev=False):
'''
defsorttuple function sorts tuple varible based on key
'''
tup.sort(key=lambda x: x[key], reverse=rev)
return tup
def states_list():
pass
# Function to Display sorted states based on states list
def display_sorted_states(states):
'''
defdisplaysortedstates function used to display sorted states
on list state,capital,population,flower displayed'''
# Sort the states' table with state name alphabetically
states = sort_tuple(states, 0)
# Print States, Capital, Population, and Flower
print("State ", " Capital ", " Population ", " Flower "),
# Print values for States, Capital, Population, and Flower
for i in range(0, len(states)):
print(states[i][0], states[i][1], states[i][2], states[i][3])
# Function to search and display a particular state details
def search_state_display(state_name):
'''
defsearchstatedisplay function to search and display
speccific state,capital,population and flower image
if state not found message appears'''
state_found = 0
print("Searching State...:", state_name)
print("State ", " Capital ", " Population ", " Flower "),
for i in range(0, len(states)):
if state_name[0].strip() == states[i][0].strip().lower():
print(states[i][0], states[i][1], states[i][2], states[i][3])
img = Image.open(flowers[states[i][0].title()])
img.show()
state_found = 1
break
if state_found == 0:
print("State Not Found")
image_dir = os.path.join(sys.path[0], 'flowers')
flowers = dict()
for i in range(0, len(states)):
flowers[states[i][0]] = os.path.join(image_dir, states[i][3] + '.jpeg')
# Display Bar graph of the top 5 populated States showing their overall population
def display_bar_graph_top5(states):
'''
defdisplaybargraphtop5 function to display a bar graph
of top 5 state populations'''
# Sort the state with population
states = sort_tuple(states, 2, True)
# Get top 5 state name and population in array from sorted state list
states_name = []
states_population = []
for i in range(0, 5):
states_name.append(states[i][0].strip())
states_population.append(states[i][2])
# Plot the graph
plt.bar(states_name[0:5], states_population[:5], color='blue', width=0.4)
plt.ylabel('State Population')
plt.xlabel('States_Name')
plt.show()
# Function to update the population of states
def update_population(states, state_name, population):
'''
defupdatepopulation function updates the states population
if state not found message appears'''
# Update the overall state population for a specific state.
state_found = 0
index = 0
for i in range(0, len(states)):
if state_name[0].strip() == states[i][0].strip().lower():
state_name = states[i][0]
state_capital = states[i][1]
state_population = states[i][2]
state_flower = states[i][3]
state_found = 1
index = i
break
if state_found == 1:
states.pop(index)
states.insert(index, (state_name, state_capital, int(population[0]), state_flower))
else:
print("State not found in the list")
# main program
# initialize user input to 1
user_input = 1
# loop till user_input is 5
while True:
# Display Menu to user
print('Hello, please make a selection')
print('1. Display all U.S. States in Alphabetical order '
'along with the Capital, State Population, and Flower '),
print('2. Search for a specific state and display the '
'appropriate Capital name, State Population, and an image '
'of the associated State Flower. '),
print('3. Provide a Bar graph of the top 5 populated States showing '
'their overall population '),
print('4. Update the overall state population for a specific state. '),
print('5. Exit the program '),
# get user choice
try:
USER_INPUT = int(input('Enter choices : '))
except:
print("Invalid option selected")
if USER_INPUT == 1:
display_sorted_states(states)
elif USER_INPUT == 2:
# Search for a specific state and display the appropriate Capital name,
# State Population, and an image of the
# associated State Flower.
state_name = input('Input the State: ').lower(),
search_state_display(state_name)
elif USER_INPUT == 3:
# Bar graph of the top 5 populated States showing their overall population
display_bar_graph_top5(states)
elif USER_INPUT == 4:
# Update the overall state population for a specific state.
state_name = input('Input the State: ').lower(),
population = input('Input Population: ').lower(),
update_population(states, state_name, population)
elif USER_INPUT == 5:
# Exit the program
print("Goodbye")
sys.exit()
else:
print("Invalid input, try again")

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial Accounting For Management

Authors: Paresh Shah

2nd Edition

0198077033, 978-0198077039

More Books

Students also viewed these Accounting questions