Question

In: Computer Science

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:

  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 program, you can assume that the user will not enter duplicate author names

Solutions

Expert Solution

author_name = ""

author_novels = ""

list_author_names = []

list_author_novels = []


title = input("Enter a title for the data:")

print("You entered: " + title)

column_author_name = input("Enter the column 1 header:")

print("You entered: " + column_author_name)

column_author_novles = input("Enter the column 2 header:")

print("You entered: " + column_author_novles)


def getDataPoints() :

    data_point = '0'

    try :

        while data_point != '-1' :

            valid_data_point = []

            data_point = input("Enter a data point (-1 to stop input):")

            print("You entered: " + data_point)

            if len(data_point) <= 2 and int(data_point) == -1:

                break

            

            valid_data_point = data_point.split(",")

            if len(valid_data_point) < 2 :

                print("Error: No comma in string.")

                pass

            elif len(valid_data_point) == 2:

                author_name = valid_data_point[0]

                list_author_names.append(author_name.strip())

                author_novels = valid_data_point[1]

                list_author_novels.append(author_novels.strip())

            elif len(valid_data_point) > 2 :

                pass            

    except:

        print("There is an exception")

def showAuthorInformationTable() :

    print("{0:^33}".format(title))

    print("{0:^20} | {1:^23}".format(column_author_name, column_author_novles))

    print("---------------------------------------------------------------------")

    for i in range(len(list_author_names)) :

        print("{0:^20} | {1:^23}".format(list_author_names[i], list_author_novels[i]))

def showAuthorInformationHistogram() :

    for i in range(len(list_author_names)) :

        print("{0:>30}    {1:<10}".format(list_author_names[i],int(list_author_novels[i])*"*"))


#Get Data Points from user

getDataPoints()

#Display Author information in a tabular format

showAuthorInformationTable()

#Display Author information in a histogram format

showAuthorInformationHistogram()




Related Solutions

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: Prompt the user for the information about the table. First, ask for the title of this data set by prompting the user...
This program is written by Ruby and Please rewrite this program as python. input_lines = gets.split("...
This program is written by Ruby and Please rewrite this program as python. input_lines = gets.split(" ") tasizan = input_lines[0].to_i hikizan = input_lines[1].to_i cnt=-0 drill=[] while cnt<tasizan kazu1 = rand(100) kazu2 = rand(100) next if kazu1+kazu2>99 next if drill.include?("#{kazu1} + #{kazu2} =") drill.push("#{kazu1} + #{kazu2} =") cnt+=1 end cnt=0 while cnt<hikizan kazu1 = rand(100) kazu2 = rand(100) next if kazu1 <= kazu2 next if drill.include?("#{kazu1} - #{kazu2} =") drill.push("#{kazu1} - #{kazu2} =") cnt+=1 end puts drill.sample(tasizan+hikizan)
(CODE IN PYTHON) Program Input: Your program will display a welcome message to the user and...
(CODE IN PYTHON) Program Input: Your program will display a welcome message to the user and a menu of options for the user to choose from. Welcome to the Email Analyzer program. Please choose from the following options: Upload text data Find by Receiver Download statistics Exit the program Program Options Option 1: Upload Text Data If the user chooses this option, the program will Prompt the user for the file that contains the data. Read in the records in...
Meant to be written in Java JDK 14.0 Write a program to display the conversion table...
Meant to be written in Java JDK 14.0 Write a program to display the conversion table from meter to feet using formatted output (printf()): 1 meter = 3.28084 feet; 1 foot = 12 inch When display the number, round the number to 2 decimal places. Set the number in the 1st the 2nd columns to the left align, set the 3rd column to the right align: meter(s) feet inch(es) 1 3.28 37.37 2 x.xx xx.xx 3 x.xx xxx.xx
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.
Given a list of negative integers, write a Python program to display each integer in the...
Given a list of negative integers, write a Python program to display each integer in the list that is evenly divisible by either 5 or 7. Also, print how many of those integers were found. Sample input/output: Enter a negative integer (0 or positive to end): 5 Number of integers evenly divisible by either 5 or 7: 0 Sample input/output: Enter a negative integer (0 or positive to end): -5 -5 is evenly divisible by either 5 or 7. Enter...
Beginning Python Programming - Sorting: Write and test a Python program to print a set of...
Beginning Python Programming - Sorting: Write and test a Python program to print a set of real numbers in descending order. The program should also print out the median of the numbers input and how many numbers were input. The program should read in numbers until a negative number is read. The negative number serves as a sentinel or marker telling the program when to stop reading numbers. The program should then sort the numbers and print them out in...
IN PYTHON Develop a program in python that includes a number of functions for the multi-server...
IN PYTHON Develop a program in python that includes a number of functions for the multi-server queue. The program accepts arrival and services rates and the number of servers and calls your functions to output the average number of customers and average waiting time in the system.
Python program. Write a python program that can convert any radix-d (arbitrary base) number to the...
Python program. Write a python program that can convert any radix-d (arbitrary base) number to the equivalent radix-e (another arbitrary base) number. Where e and d are members in [2, 16]. Remember, base 16 needs to be calculated as hexadecimal. So, if radix-d is input as a hexadecimal number, it needs to convert and output to desired base. Conversely, if base 16 is the desired output, then the output needs to show a hexadecimal number. Hints: The easiest approach is...
Using Python, create a program that will act as a number convertor. This program will convert...
Using Python, create a program that will act as a number convertor. This program will convert an input decimal integer into binary and hexadecimal formats. a) Define a main function named numberconvertor(). Inside the main function, write all the logic of your code. [5% marks] b) Looping indefinitely (Hint: use infinite while loop), the program should give the user the 3 options given below and allow the user to select one among them. [15% marks] 1. converting a decimal number...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT