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 2 header:
Number of novels
You entered: Number of novels
(2) Write a function, get_data_points(), that
prompts the user for data points, and returns a dictionary
where the keys are the string component of the data points, and the
values are the integer component of the 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 on each iteration. (4
pts)
Ex:
Enter a data point (-1 to stop input):
Jane Austen, 6
Data string: Jane Austen
Data integer: 6
(3) Improve the get_data_points() function by
performing error checking for the data point entries. If any of the
following errors occurs, output the appropriate error message and
prompt again for a valid data point.
Ex:
Enter a data point (-1 to stop input):
Ernest Hemingway 9
Error: No comma in string.
Enter a data point (-1 to stop input):
Ernest, Hemingway, 9
Error: Too many commas in input.
Enter a data point (-1 to stop input):
Ernest Hemingway, nine
Error: Comma not followed by an integer.
Enter a data point (-1 to stop input):
Ernest Hemingway, 9
Data string: Ernest Hemingway
Data integer: 9
(4) Write a function, print_data(), that takes the
table header information list created in (1) and the
dictionary created in (3). The function will output the
information in a formatted table. The title is right justified with
a minimum field width value of 33. Column 1 has a minimum field
width value of 20. Column 2 has a minimum field width value of 23.
(3 pts)
Ex:
Number of Novels Authored
Author name | Number of novels
--------------------------------------------
Jane Austen | 6
Charles Dickens | 20
Ernest Hemingway | 9
Jack Kerouac | 22
F. Scott Fitzgerald | 8
Mary Shelley | 7
Charlotte Bronte | 5
Mark Twain | 11
Agatha Christie | 73
Ian Flemming | 14
J.K. Rowling | 14
Stephen King | 54
Oscar Wilde | 1
(6) Write a function, print_histogram(), to output
the data point information formatted as a
histogram. Each name is right justified with a minimum
field width value of 20. (4 pts)
Ex:
Jane Austen ******
Charles Dickens ********************
Ernest Hemingway *********
Jack Kerouac **********************
F. Scott Fitzgerald ********
Mary Shelley *******
Charlotte Bronte *****
Mark Twain ***********
Agatha Christie *************************************************************************
Ian Flemming **************
J.K. Rowling **************
Stephen King ******************************************************
Oscar Wilde *
The main format should be restrict it as the following:
if __name__ == '__main__':
# Below 4 lines are required for basic test cases. Do not delete them.
headers = get_data_headers()
data = get_data_points()
print_data(headers, data)
print_histogram(data)
thanks for the question, here is the complete code in python
========================================================================================
def get_data_headers():
title =input('Enter a title for the
data:')
print('You entered:
{}'.format(title))
headerOne=input('\nEnter the column 1
header: ')
print('You entered:
{}'.format(headerOne))
headerTwo=input('\nEnter the column 2
header: ')
print('You entered:
{}'.format(headerTwo))
return
[title,headerOne,headerTwo]
def get_data_points():
data_point_dict={}
while True:
data=input('Enter a data point (-1 to stop input):
')
if data
=='-1':
break
elif ',' not in
data:
print('Error:
No comma in string.\n')
elif
data.count(',')>1:
print('Error: Too many commas in input.\n')
else:
data=data.split(',')
try:
data_point_dict[data[0].strip()] = int(data[1])
print('Data string: {}'.format(data[0]))
print('Data integer: {}'.format(data[1]))
except:
print('Error: Comma not followed by an
integer.\n')
return data_point_dict
def print_data(header,data_points):
print('{0:^50}'.format(header[0]))
print('{0:<24}{1:^1}{2:>25}'.format(header[1],'|',header[2]))
print('='*50)
for key,value
in data_points.items():
print('{0:<24}{1:^1}{2:>25}'.format(key,'|',value))
def print_histogram(data_points):
print('\n\n')
for key,value
in data_points.items():
print('{0:<24}
{1}'.format(key,'*'*value))
def main():
headers=get_data_headers()
data_points=get_data_points()
print_data(headers,data_points)
print_histogram(data_points)
main()
========================================================================================
thanks !
import java.util.Scanner; import java.util.ArrayList; import java.util.List; public class DataVisualizer { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); ArrayList<String> authorName = new ArrayList<String>(); ArrayList<String> numBooks = new ArrayList<String>(); String title; String col1; String col2; String dataPoints; int commaLocation; String author; String numNovels; int bookStars; System.out.println("Enter a title for the data:"); title = scnr.nextLine(); System.out.println("You entered: " + title); System.out.println(); System.out.println("Enter the column 1 header:"); col1 = scnr.nextLine(); System.out.println("You entered: "+ col1); System.out.println(); System.out.println("Enter the column 2 header:"); col2 = scnr.nextLine(); System.out.println("You entered: " + col2); System.out.println(); do { System.out.println("Enter a data point (-1 to stop input):"); dataPoints = scnr.nextLine(); if (dataPoints.equals("-1")) { break; } else if (!dataPoints.contains(",")) { System.out.println("Error: No comma in string."); System.out.println(); continue; } else if (!dataPoints.matches(".*\\d.*")) { System.out.println("Error: Comma not followed by an integer."); System.out.println(); continue; } else if (dataPoints.contains(",")) { int count = 0; int location; for (int m = 0; m < dataPoints.length(); m++) { if(dataPoints.charAt(m) == ',') { count++; } } if (count > 1) { System.out.println("Error: Too many commas in input."); System.out.println(); continue; } else if (count == 1) { commaLocation = dataPoints.indexOf(','); author = dataPoints.substring(0, commaLocation); numNovels = dataPoints.substring(commaLocation + 1, dataPoints.length()); author = author.trim().replaceAll(" +", " "); numNovels = numNovels.trim().replaceAll(" +", " "); System.out.println("Data string: " + author); System.out.println("Data integer: " + numNovels); System.out.println(); authorName.add(author); numBooks.add(numNovels); continue; } } else { commaLocation = dataPoints.indexOf(','); author = dataPoints.substring(0, commaLocation); numNovels = dataPoints.substring(commaLocation + 1, dataPoints.length()); author = author.trim().replaceAll(" +", " "); numNovels = numNovels.trim().replaceAll(" +", " "); System.out.println("Data string: " + author); System.out.println("Data integer: " + numNovels); System.out.println(); authorName.add(author); numBooks.add(numNovels); } } while (!dataPoints.equals("-1")); System.out.println(); System.out.printf("%33s\n", title); System.out.printf("%-20s|%23s\n", col1, col2); System.out.println("--------------------------------------------"); for (int i = 0; i < authorName.size(); i++) { System.out.printf("%-20s|%23s\n", authorName.get(i), numBooks.get(i)); } System.out.println(); for (int j = 0; j < authorName.size(); j++) { System.out.printf("%20s ", authorName.get(j)); bookStars = Integer.parseInt(numBooks.get(j)); for (int k = 0; k < bookStars; k++) { System.out.print("*"); } System.out.println(); } } }
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....
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...
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...
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...
**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....
Please help modify my C program to be able to answer these questions, it seems the spacing and some functions arn't working as planeed. Please do NOT copy and paste other work as the answer, I need my source code to be modified. Source code: #include <stdio.h> #include <string.h> #include <ctype.h> #include <stdlib.h> int main(void) { char title[50]; char col1[50]; char col2[50]; int point[50]; char names[50][50]; printf("Enter a title for the data:\n"); fgets (title, 50, stdin); printf("You entered: %s\n", title);...
*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: Prompt the user for information about the table. First, ask for the title of this data set by prompting the user for a title for data, and then output the...
I need help with this assignment in C++, please! *** The instructions and programming style details are crucial for this assignment! Goal: Your assignment is to write a C+ program to read in a list of phone call records from a file, and output them in a more user-friendly format to the standard output (cout). In so doing, you will practice using the ifstream class, I'O manipulators, and the string class. File format: Here is an example of a file...
could you please help me with this problem, also I need a little text so I can understand how you solved the problem? import java.io.File; import java.util.Scanner; /** * This program lists the files in a directory specified by * the user. The user is asked to type in a directory name. * If the name entered by the user is not a directory, a * message is printed and the program ends. */ public class DirectoryList { public static...
> Thank you!!
Kabelo Dike Tue, Feb 1, 2022 3:33 PM