Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need Help I\'ve got 10/17 on this assignment! Assignment -----------------------

ID: 3717085 • Letter: N

Question

Need Help I've got 10/17 on this assignment!

Assignment -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

7.7 Ch 7 Program: Data visualization (Python 3)

(1) Prompt the user for a title for data. Output the title. (1 pt)

Ex:


(2) Prompt the user for the headers of two columns of a table. Output the column headers. (1 pt)

Ex:


(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 a list of strings. Store the integer components of the data points in a list of integers. (4 pts)

Ex:


(4) Perform 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.

If entry has no comma

Output: Error: No comma in string. (1 pt)

If entry has more than one comma

Output: Error: Too many commas in input. (1 pt)

If entry after the comma is not an integer

Output: Error: Comma not followed by an integer. (2 pts)


Ex:


(5) 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:


(6) Output the information as a formatted histogram. Each name is right justified with a minimum field width value of 20. (4 pts)

Ex:

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

It looks like I'm suppose to have a Line here, But I can't seem to fix it.

code I have so far ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

def checkCommas(dataPoint):

if ',' not in dataPoint:
  
print('Error: No comma in string.')
return False

elif dataPoint.count(",") > 1:

print('Error: Too many commas in input.')
return False

else:

index = dataPoint.find(",")
  
name = dataPoint.split(",")[0]
integer = (dataPoint.split(",")[1]).strip()
  
if not (integer.isdigit()):

print('Error: Comma not followed by an integer.')
return False
else:
return True

def table(title, header1, header2, nameList, numberList):

print('%33s' %(title))

print('%-20s %-10s %-23s'%(header1, "|", header2))
print("----------------------------------------------------")

for i in range(0, len( nameList)):
print("%-20s %-10s %-23d " %(nameList[i], "|", numberList[i]))
print(' ')


def histogram( nameList, numberList):

for i in range(0, len( nameList)):
print(' %20s %-5s'%( nameList[i], " "), end = "")
for j in range(0, numberList[i]):
print("*", end="")
print(' ')


def main():
nameList = []
numberList = []


title = input('Enter a title for the data: ')
print('You entered: ' + title)


header1 = input(' Enter the column 1 header: ')
print('You entered: ' + header1)


header2 = input(' Enter the column 2 header: ')
print('You entered: ' + header2)


dataPoint = input(' Enter a data point (-1 to stop input): ')
while dataPoint != '-1':
  
commas = checkCommas(dataPoint)
  
if commas:
name = dataPoint.split(",")[0]
integer = int((dataPoint.split(",")[1]).strip())

print("Data string: " + name)
print("Data integer: " + str(integer))

nameList.append(name)
numberList.append(integer)
  
dataPoint = input(' Enter a data point (-1 to stop input): ')



table(title, header1, header2, nameList, numberList)
  

histogram(nameList, numberList)


main()

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 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 I Mary Shelley Charlotte Bronte Mark Twain Agatha Christie Ian Fleming J.K. Rowling

Explanation / Answer

Awesome work you have done.

I have added a new line at the mentioned point as per my understanding and also "--------------------" just at beginning of table function.

def checkCommas(dataPoint):

if ',' not in dataPoint:
  
print('Error: No comma in string.')
return False

elif dataPoint.count(",") > 1:

print('Error: Too many commas in input.')
return False

else:

index = dataPoint.find(",")
  
name = dataPoint.split(",")[0]
integer = (dataPoint.split(",")[1]).strip()
  
if not (integer.isdigit()):

print('Error: Comma not followed by an integer.')
return False
else:
return True

def table(title, header1, header2, nameList, numberList):
print(" ----------------------------------------------------")
print('%33s' %(title))

print('%-20s %-10s %-23s'%(header1, "|", header2))
print("----------------------------------------------------")

for i in range(0, len( nameList)):
print("%-20s %-10s %-23d " %(nameList[i], "|", numberList[i]))
print(' ')


def histogram( nameList, numberList):

for i in range(0, len( nameList)):
str1=""
print(' %20s %-5s'%( nameList[i], " "), end = "")
for j in range(0, numberList[i]):
print("*", end="")

  
print(' ')


def main():
nameList = []
numberList = []


title = input('Enter a title for the data: ')
print('You entered: ' + title)


header1 = input(' Enter the column 1 header: ')
print('You entered: ' + header1)


header2 = input(' Enter the column 2 header: ')
print('You entered: ' + header2)


dataPoint = input(' Enter a data point (-1 to stop input): ')
while dataPoint != '-1':
  
commas = checkCommas(dataPoint)
  
if commas:
name = dataPoint.split(",")[0]
integer = int((dataPoint.split(",")[1]).strip())

print("Data string: " + name)
print("Data integer: " + str(integer))

nameList.append(name)
numberList.append(integer)
  
dataPoint = input(' Enter a data point (-1 to stop input): ')


table(title, header1, header2, nameList, numberList)
  

histogram(nameList, numberList)


main()

# Please let me know if anything else was requirement so that I can rectify it in comment section. Rest your code is perfect.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote