In: Computer Science
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:
Enter a title for the data: Number of Novels Authored You entered: Number of Novels Authored
Enter the column 1 header: Author name You entered: Author name Enter the column 2 header: Number of novels You entered: Number of novels
Enter a data point (-1 to stop input): Jane Austen, 6 Author: Jane Austen Number of Novel(s): 6
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
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
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
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()