Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, For Data visualization(Pyhton3 ), I am getting the following errors:(please see screenshot). My code: # function to check commas def checkCommas(dataPoint): # to check

Hello,

For "Data visualization(Pyhton3image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed), I am getting the following errors:(please see screenshot).

My code:

# function to check commas def checkCommas(dataPoint): # to check if there is comma or not if ',' not in dataPoint: # Display an error message "No comma in string" print('Error: No comma in string.') return False # to check if the datapoint has more than one comma elif dataPoint.count(",") > 1: # Display an error message "Too many commas in input" print('Error: Too many commas in input.') return False # to check if there an integer after comma else: # find index. index = dataPoint.find(",") # split the datapoint name = dataPoint.split(",")[0] integer = (dataPoint.split(",")[1]).strip() # to check if the number is integer or not. if not (integer.isdigit()): # Display an error message "Comma not followed by an integer" print('Error: Comma not followed by an integer.') return False else: return True

# function definition of table() which prints the information in a formatted table def table(title, header1, header2, nameList, numberList): # to print the title print(" %33s " %(title)) # to print the header print(" %-20s %-10s %-23s " %(header1, "|", header2)) print("--------------------------------------------") # to print the list in formatted table for i in range(0, len( nameList)): print("%-20s %-10s %-23d " %(nameList[i], "|", numberList[i])) print(" ")

# function definition of histogram() which prints the information as a formatted histogram def histogram( nameList, numberList): # to print the list as a formatted histogram for i in range(0, len( nameList)): print(" %20s %-5s " %( nameList[i], " "), end = "") for j in range(0, numberList[i]): print("*", end="")

# main function def main(): nameList = [] # to hold the string part of the data points. numberList = [] # to hold the integer part of the data points.

# Prompt the user to enter a title for data title = input('Enter a title for the data: ') print("You entered: " + title)

# Prompt the user to enter the header for column 1 of a table header1 = input(' Enter the column 1 header: ') print("You entered: " + header1)

# Prompt the user to enter the header for column 1 of a table header2 = input(' Enter the column 2 header: ') print("You entered: " + header2)

# Prompt the user to enter data points dataPoint = input(" Enter a data point (-1 to stop input): ") while dataPoint != "-1": # Call to the function to check for commas commas = checkCommas(dataPoint) #if there is only one comma and data entered is correct,split the data if commas: name = dataPoint.split(",")[0] integer = int((dataPoint.split(",")[1]).strip()) # Print the datapoint on console print("Data string: " + name) print("Data integer: " + str(integer)) # Store data in the list nameList.append(name) numberList.append(integer) # Prompt the user to enter data points dataPoint = input(" Enter a data point (-1 to stop input): ")

# to output the information in a formatted table, call the function table() table(title, header1, header2, nameList, numberList) # to output the information as a formatted histogram, call the function histogram() histogram(nameList, numberList)

# Call the main function. main()

Your output starts Data integer: 11 with Enter a data point (-1 to stop input): Error: Comma not followed by an integer. Enter a data point (-1 to stop input): Error: Comma not followed by an integer Enter a data point (-1 to stop input): Error: Comma not followed by an integer Enter a data point (-1 to stop input) Data string: Agatha Christie Data integer: 73 Enter a data point (-1 to stop input) Data string: Ian Flemming Data integer: 14 Enter a data point (-1 to stop input) Data string: J.K. Rowling Data integer: 14 Enter a data point (-1 to stop input): Data string: Stephen King Data integer: 54 Enter a data point (-1 to stop input): Data string: Oscar Wilde Data integer:1 Enter a data point (-1 to stop input) Number of Novels Authored uthor name of novels 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 11de Enter a title for the data: You entered: Number of Novels Authored Expected output Enter a data point (l to stop input) starts with Data string: Mark Twain Data integer: 11 Enter a data point (-1 to stop input) Error: Comma not followed by an integer Enter a data point (-1 to stop input) Error: Comma not followed by an integer Enter a data point (-1 to stop input) Error: Comma not followed by an integer Enter a data point (-1 to stop input) Data string: Agatha Christie Data integer: 73 Enter a data point (-1 to stop input) Data string: Ian Flemming Data integer: 1 Enter a data point (-1 to stop input) Data string: J.K. Rowling Data integer: 1 Enter a data point (-1 to stop input) Data string: Stephen King Data integer: 5 Enter a data point (-1 to stop input) Data string: Oscar Wilde Data integer: Enter a data point (-1 to stop input) Number of Novels Authored Author name Number of novels Jane Austen Charles Dickens Ernest HemingwayI Jack Kerouac F. Scott Fitzgerald Mary Shelley Charlotte Bronte I Mark Twain Agatha Christie Ian Flemming J.K.Rowling Stephen King | Oscar Wilde Number of Novels Author Author nameNumber of no ane Austen Charles Dickens Ernest Hemingway Jack Kerouac F. Scott Fitzgerald Mary Shelley charlotte Bronte Mark Tvain Agatha Christie Ian Flemmin J.K. Rowling 14 ut ends Stephen King with Oscar Wilde Jane Auste Charles Dicken Ernest Hemingwa Jack Keroua F. Scott Fitzgeral Mary Shelle Charlotte Bront Hark Twai Agatha Christi Ian Flenmin J.K. Rowlin Stephen Kin Oscar Nild Number of Novels Authored Author name Number of novels Jane Austen Charles Dickens Ernest Hemingway Jack Kerouac P. Scott Fitzgerald Mary Shelley Charlotte Bronte Mark Twain Agatha Christie Ian Flemming J.K. Rowling Expected output Stephen King ends with Oscar Wilde Jane Austen* Charles Dickens ** Ernest Hemingway 9: Compare output 0/2 Output differs. See highlights below. Special character legend Number of Musicals Written Author name umber of musicals Stephen Sondheim, 19 Leonard Bernstein, Elton John, Input Andrew L Webber, 17 Galt MacDernot, 8 Jonathan Larson, 2 John Kander, 25 Alain Boublil, 3 umber of Musicals Written Author name INumber of musical Stephen Sondhe im Leonard Bernstein Elton John 19 Andrew L Webber Galt MacDernot Jonathan LarsonI Your output ends John Kander Alain Boublil Stephen Sondhei Leonard Bernstei Elton Jo Andrew L Webbe Galt Mac Dermo Jonathan Larso John Kande Alain Boubli Number of Musicals ritten Author name I Number of nusicals Stephen Sondheim Leonard Bernstein Elton John Andrew L Webber Galt MacDernot Jonathan Larson Expected output John Kander ends withAlain Boublil stephen Sondheim

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Define span of management or define span of control ?

Answered: 1 week ago