Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Homework5 (20pts) File Edit Format Run Options Window Help #Define calc_percentage def calc_percentage (#add parameters) : Write a python program that prompts the user for

image text in transcribed

Homework5 (20pts) File Edit Format Run Options Window Help \#Define calc_percentage def calc_percentage (\#add parameters) : Write a python program that prompts the user for the current US population, and the names and populations of five major cities (in different states). Your program will calculate the percentage of each city's population based on total Example Input: \# code US population. The program will display a table with the state, city name, city population, and city population percentage. Enter US Population: 332403650 \#Define display data def display_data(\#add parameters) : Include the following component in your solution Enter City: Chicago \#Add code to format and display the data passed in 1. A calc_percentage() function: This function takes the US population and the Enter State: IL \#Define menu function population of a state. 4pts Enter Population: 2700000 def menu(): a. It calculates and returns the percentage of the state population in \#Start a try block to detect bad entry for us population relation to total US population 2. A display_data() function: This function will be used to display data for each Enter City: New York \#Start loop: state. Parameters for the function include the state, city, city population, Enter State: NY \#start try block to detect by entry for the state population and population percentage (returned by calc_percentage() function). The \#Prompt for the state function will format and display the data passed in as parameters 4pts \#Prompt for the city population a. State (formatted to 5 columns left aligned) \#if the state and city are not block b. City (formatted to 20 columns left aligned) \#call calc_percentage() with pass the correct parameters c. City Population (formatted to 10 columns left aligned) \#call display_data() with the correct parameters d. Population percentage formatted to 5 columns with 2 decimal places 3. A menu() function: This function takes no parameters. menu() will be the \#except block main function for the program. Include the following in the menu() function 9pts a. Prompt for the US population 1pt b. Use a loop to allow the user to enter data for each state. For each iteration of the loop do the following: i. Prompt for a city data (state, city name, city population) 2pt ii. Check whether the user entered valid values for the state and city name before attempting to process the data - state and city cannot be blank 3pts Important: If your program does not run, that's an automatic 50% deduction \#except block percentage for the state being processed 1pt iv. Store the city population percentage 1pt Homework submission details v. Call display_data() function 1pt Write your homework solution as a python script. Use the following naming convention for your homework solution file: firstinitial_lastname_homewor5.py. 4. Include try/except block to guard against bad data. For example, if the user Example: p_saweh_homework5.py enters non-numeric value for the population. I include steps 3bi3bv in a Once your homework is complete, submit it in D2L. Upload your program file into try except block 3pts homework5

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

Professional SQL Server 2012 Internals And Troubleshooting

Authors: Christian Bolton, Justin Langford

1st Edition

1118177657, 9781118177655

More Books

Students also viewed these Databases questions