*In Python please*****
This program will display some statistics, a table and a histogram of a set of cities and the population of each city. You will ask the user for all of the information. Using what you learned about incremental development, consider the following approach to create your program:
Enter a title for the data: Populations of U.S. Cities You entered: Populations of U.S. Cities
Enter the column 1 header: Name of City You entered: Name of City Enter the column 2 header: Total Population You entered: Total Population
Enter a data point ('done' to stop input): New York City, 7623000 City: New York City Population: 7623000
If the error occurs, output the appropriate error message and
prompt again for a valid data point. You can assume that if a comma
is present, then the data point is entered correctly.
Ex:
Enter a data point ('done' to stop input): Seattle 724745 Error: No comma in string. Enter a data point ('done' to stop input): Seattle , 724745 City: Seattle Population: 724745
Population Statistics Minimum: 48844 Maximum: 8623000 Mean: 3417614.666
Population of US Cities Name of City | Total Population ---------------------------------- New York City | 7623000 Seattle | 724745 Philadelphia | 1581000 Minneapolis | 422331 Cleveland | 385525 Los Angeles | 4000000
New York City **************************************************************************** Seattle ******* Philadelphia *************** Minneapolis **** Cleveland *** Los Angeles ****************************************
For this project, you can assume that the user will not enter duplicate city names.
This project has one hidden test case, that will not give you any type of feedback. If you are not able to pass the hidden test case, make sure that your program is set up to use any input. It is likely you are hard-coding some part of your program if you are not able to pass the hidden test case. Do not get frustrated. Instead, be sure to ask questions in class, in the helproom, or using Piazza.
Here's an example of the full program:
Enter a title for the data: Populations of U.S. Cities You entered: Populations of U.S. Cities Enter the column 1 header: Name of City You entered: Name of City Enter the column 2 header: Total Population You entered: Total Population Enter a data point ('done' to stop input): New York City, 7623000 City: New York City Population: 7623000 Enter a data point ('done' to stop input): Seattle , 724745 City: Seattle Population: 724745 Enter a data point ('done' to stop input): Philadelphia 1581000 Error: No comma in string. Enter a data point ('done' to stop input): Philadelphia, 1581000 City: Philadelphia Population: 1581000 Enter a data point ('done' to stop input): Minneapolis, 382578 City: Minneapolis Population: 382578 Enter a data point ('done' to stop input): Cleveland, 396698 City: Cleveland Population: 396698 Enter a data point ('done' to stop input): Los Angeles, 3793000 City: Los Angeles Population: 3793000 Enter a data point ('done' to stop input): done Enter the character for the histogram: * Population Statistics Minimum: 382578 Maximum: 7623000 Mean: 2416836.833 Population of US Cities Name of City | Total Population ---------------------------------- New York City | 7623000 Seattle | 724745 Philadelphia | 1581000 Minneapolis | 382578 Cleveland | 396698 Los Angeles | 3793000 New York City **************************************************************************** Seattle ******* Philadelphia *************** Minneapolis *** Cleveland *** Los Angeles *************************************
We can decompose the problem to eight functions -
I have shared the code below:
# main function
def main():
title = get_title()
headers = get_header()
data = get_data()
c = get_character()
print_stats(data[1])
print_table(title, headers, data)
print_histogram(data, c)
# returns title
def get_title():
title = input("Enter a title for the data:\n")
print("You entered:", title)
print()
return title
# returns all the header columns as a list
def get_header():
col1 = input("Enter the column 1 header:\n")
print("You entered:", col1)
print()
col2 = input("Enter the column 2 header:\n")
print("You entered:", col2)
print()
return [col1, col2]
# returns the data as a list
def get_data():
cities = []
populations = []
while True:
line = input("Enter a data point
('done' to stop input):\n")
if (line.lower() == "done"):
break
# validate
if "," not in line:
print("Error: No
comma in string.")
print()
continue
city, population =
line.strip().split(",")
# add to list
city = city.strip()
cities.append(city)
population =
int(population.strip())
populations.append(population)
print("City:", city)
print("Population:",
population)
print()
return [cities, populations]
# returns the character used for histogram
def get_character():
print()
c = input("Enter the character for the histogram:
")
print()
return c
# prints the statistics
def print_stats(populations):
print("Population Statistics")
print("Minimum:".rjust(8), min(populations))
print("Maximum:".rjust(8), max(populations))
print("Mean:".rjust(8), round(sum(populations) /
len(populations), 3))
print()
# prints the data in table format
def print_table(title, headers, data):
print(title.rjust(27))
print(headers[0].rjust(16) + "|" +
headers[1].rjust(17))
print("----------------------------------")
cities = data[0]
populations = data[1]
# print data
for i in range(len(cities)):
print(cities[i].rjust(16) + "|" +
str(populations[i]).rjust(17))
print()
# displays the histogram of the data using the passed
character
def print_histogram(data, c):
cities = data[0]
populations = data[1]
for i in range(len(cities)):
# the character is multiplied by a
factor of population / 100000
print(cities[i].rjust(16), c *
int(round(populations[i]/100000)))
main()
Code Screenshot:
Code Execution:
*In Python please***** This program will display some statistics, a table and a histogram of a...
11.9 LAB*: Program: Data visualization(1) Prompt the user for a title for data. Output the title. (1 pt)Ex:Enter a title for the data: Number of Novels Authored You entered: Number of Novels Authored(2) Prompt the user for the headers of two columns of a table. Output the column headers. (1 pt)Ex:Enter the column 1 header: Author name You entered: Author name Enter the column 2 header: Number of novels You entered: Number of novels(3) Prompt the user for data points. Data points must be in this format: string, int. Store the information before the comma into a string variable and the information after the comma into an integer. The user will enter -1 when they...
5.10 LAB*: Program: Data visualization(1) Prompt the user for a title for data. Output the title. (1 pt)Ex:Enter a title for the data: Number of Novels Authored You entered: Number of Novels Authored(2) Prompt the user for the headers of two columns of a table. Output the column headers. (1 pt)Ex:Enter the column 1 header: Author name You entered: Author name Enter the column 2 header: Number of novels You entered: Number of novels(3) Prompt the user for data points. Data points must be in this format: string, int. Store the information before the comma into a string variable and the information after the comma into an integer. The user will enter -1 when they...
Need help with this homework, and follow the bolded text required 7.10 LAB: Data Visualization (1) Write a function, get_data_headers(), to prompt the user for a title, and column headers for a table. Return a list of three strings, and print the title, and column headers. (2 pt) Ex: Enter a title for the data: Number of Novels Authored You entered: Number of Novels Authored Ex: Enter the column 1 header: Author name You entered: Author name Enter the column...
In this assignment you are going to handle some basic input operations including validation and manipulation, and then some output operations to take some data and format it in a way that's presentable (i.e. readable to human eyes). Functions that you will need to use: getline(istream&, string&) This function allows you to get input for strings, including spaces. It reads characters up to a newline character (for user input, this would be when the "enter" key is pressed). The first...
Python 3.1 - 3.5 Certain machine parts are assigned serial numbers. Valid serial numbers are of the form: SN/nnnn-nnn where ‘n’ represents a digit. Write a function valid_sn that takes a string as a parameter and returns True if the serial number is valid and False otherwise. For example, the input "SN/5467-231" returns True "SN5467-231" returns False "SN/5467-2231" returns False Using this function, write and test another function valid-sn-file that takes three file handles as input parameters. The first handle...
PYTHON Text file Seriesworld attached below and it is a list of teams that won from 1903-2018. First time mentioned won in 1903 and last team mentioned won in 2018. World series wasn’t played in 1904 and 1994 and the file has entries that shows it. Write a python program which will read this file and create 2 dictionaries. The first key of the dictionary should show name of the teams and each keys value that is associated is the...
The average number of minutes Americans commute to work is 27.7 minutes (Sterling's Best Places, April 13, 2012). The average commute time in minutes for 48 cities are as follows: Click on the datafile logo to reference the data. DATA file Albuquerque Atlanta Austin Baltimore Boston Charlotte Chicago Cincinnati Cleveland Columbus Dallas Denver Detroit El Paso Fresno Indianapolis 23.3 28.3 24.6 32.1 31.7 25.8 38.1 24.9 26.8 23.4 28.5 28.1 29.3 24.4 23.0 24.8 Jacksonville Kansas City Las Vegas Little...
**C programming Language 3) Prompt the user for data points. Data points must be in this format: string, int. Store the information before the comma into a string variable and the information after the comma into an integer. The user will enter -1 when they have finished entering data points. Output the data points. Store the string components of the data points in an array of strings. Store the integer components of the data points in an array of integers....
6.6 Warm up: Parsing strings (Python 3) (1) Prompt the user for a string that contains two strings separated by a comma. (1 pt) Examples of strings that can be accepted: Jill, Allen Jill , Allen Jill,Allen Ex: Enter input string: Jill, Allen (2) Report an error if the input string does not contain a comma. Continue to prompt until a valid string is entered. Note: If the input contains a comma, then assume that the input also contains two...
Write the program in C The following statistics for cities of the Vege country are stored in a file: Name: a string of characters less than 15 characters long. Population: an integer value. Area: square miles of type double Write a program that: asks and gets the name of the input file from the user. Read the contents of the file into an array length 10 of structures -ask the user for the name of a city (less than 15...