Question

In: Computer Science

23.2 PROJECT 2 : Data Visualization using LOOPS (python) This program will display a set of...

23.2 PROJECT 2 : Data Visualization using LOOPS (python)

This program will display a set of authors and the number of novels written by each author in both a table and a histogram. You will ask the user for all of the information. Using what you learned about incremental development, use the following approach to create your program:

  1. Prompt the user for the information about the table. First, ask for the title of this data set by prompting the user for a title for data. Output the title.

    Ex:
Enter a title for the data:
Number of Novels Authored
You entered: Number of Novels Authored
  1. The table will have two columns; one for the authors and one for the number of novels. Prompt the user for the headers of two columns of the table. Output the column headers.

    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
  1. Prompt the user for data points. Data points must be in this format: string, int, representing the author and the number of novels written by the author. 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 a list of strings. Store the integer components of the data points in a list of integers.

    Ex:
Enter a data point (-1 to stop input):
Jane Austen, 6
Author: Jane Austen
Number of Novel(s): 6
  1. Perform error checking for the data point entries as follows:
  • If entry has no comma and is not -1
  • Output: Error: No comma in string.

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 (-1 to stop input):
Ernest Hemingway 9
Error: No comma in string.

Enter a data point (-1 to stop input):
Ernest Hemingway, 9
Author: Ernest Hemingway
Number of Novel(s): 9
  1. 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.

    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
  1. Output the information as a formatted histogram. Each name is right justified with a minimum field width value of 20.

    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 *

For this project, you can assume that the user will not enter duplicate author names.

Solutions

Expert Solution

PYTHON CODE:

# getting title from the user
title = input('Enter a title for the data:\n')
print('You entered: %s' % title)

# getting header1
header1 = input('\nEnter the column1 header:\n')
print('You entered: %s' % header1)

# getting header2
header2 = input('\nEnter the column2 header:\n')
print('You entered: %s' % header2)

# list to store the authors and number of novels
authors=[]
novels=[]

# infinite looping
while True:

    # getting input from the user
    data = input('\nEnter a data point(-1 to stop input):\n')

    # checking for valid input
    if not ',' in data and data != '-1':
        print('\nOutput: Error. No comma in string.\n')
        continue

    # breaking from the loop
    if data == '-1':
        break

    # printing the user input
    print(data)
    t=data.split(',')
    print('Author: %s' % t[0])
    print('Number of Novel(s): %s' % t[1])

    # adding the details to the list
    authors.append(t[0])
    novels.append(int(t[1]))

# printing the table headers
print("{0:>33s}".format(title))
print('{0:<20s}|{1:>23s}'.format(header1,header2))

# printing the table
for author,novel in zip(authors,novels):
    print('{0:<20s}|{1:>23d}'.format(author,novel))

print('\n')

# printing the histogram
for author,novel in zip(authors,novels):
    print('{0:>20s} '.format(author),end='')

    for i in range(novel):
        print('*',end='')
    print()
  

SCREENSHOT FOR CODING:

SCREENSHOT FOR OUTPUT:


Related Solutions

This program (in python) will display a set of authors and the number of novels written...
This program (in python) will display a set of authors and the number of novels written by each author in both a table and a histogram. You will ask the user for all of the information. Using what you learned about incremental development, use the following approach to create your program: Prompt the user for the information about the table. First, ask for the title of this data set by prompting the user for a title for data. Output the...
Write a program In python of Jupiter notebook (using loops) that prompts the user to enter...
Write a program In python of Jupiter notebook (using loops) that prompts the user to enter his/her favorite English saying, then counts the number of vowels in that (note that the user may type the saying using any combination of upper or lower case letters). Example: Enter your favorite English saying: Actions speak LOUDER than words. Number of wovels: 10
Python Language: Similar to Project 3, write a program that loops a number from 1 to...
Python Language: Similar to Project 3, write a program that loops a number from 1 to 10 thousand and keeps updating a count variable according to these rules: if the number is divisible by n1, increase count by 1 if the number is divisible by n2, increase count by 2 if the number is divisible by n3, increase count by 3 if none of the above conditions match for the number, increase count by the number. Before the loop begins,...
Write a program using python that loops over each file in a specified directory and checks...
Write a program using python that loops over each file in a specified directory and checks the size of each file.You should create 2-tuple with the filename and size, should append the 2-tuple to a list, and then store all the lists in a dictionary.  
Using python Write a program that displays all of states in the U.S. and display each...
Using python Write a program that displays all of states in the U.S. and display each state that begins with the letter A.
Intro to Python! 1. Using while loops, write a program that prints multiples of 5 which...
Intro to Python! 1. Using while loops, write a program that prints multiples of 5 which are less than 100. Your loop initially starts from 0. 2. Consider B to be a list of alphabetically ordered strings. Using while loops, write a program that only prints words which start with letter A. B = [Alex, Airplane, Alpha, Australia, Ben, Book, Bank, Circuit, Count, Dark] 3. Using while loop, create a program that only prints first 18 multiples of 7.Hint: Your...
Code in Python. You can only use while loops NOT for loops. Program 1: cost_living In...
Code in Python. You can only use while loops NOT for loops. Program 1: cost_living In 2020 the average cost of living/month (excluding housing) for a family of 4 in Pittsburgh was $3850 per month. Write a program to print the first year in which the cost of living/month is over $4450 given that it will rise at a rate of 2.1% per year. (Note:  this program requires no input). Program 2: discount A discount store is having a sale where...
Python Exercise 2 A program is to display all odd numbers between 10 and 3000. The...
Python Exercise 2 A program is to display all odd numbers between 10 and 3000. The starting value and end value are to be assigned by the programmer, not requested from user.
Write a python program to display a menu with the following options: (1) add, (2) subtract,...
Write a python program to display a menu with the following options: (1) add, (2) subtract, (3) multiply, (4) divide (5) mod, and (6) do nothing. I f the user enters something else (except 1-6), the program should display an error message. Otherwise, it should ask the user for two numbers, perform the calculation, and display the result.
Java program that display ATM booth line by using data sturcture Queue.
Java program that display ATM booth line by using data sturcture Queue.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT