In: Computer Science
Given is a Python program that connects to a sqlite database and has one table called writers with two columnns:
The writers table originally has the following data:
name, num
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
Update the Python program to ask the user if they want to update entries or add new entries. If the name entered already exists in the writers table then the database record is updated, overwriting the original contents. If the name does not exist in the writers table, then add a new record with the writer's name and number of works. The following TODO sections must be completed.
Ex: If the input is:
y
J.K. Rowling 30
y
Elton John
y
62
n
What is output. Getting nothing but errors with existing help. Again, this is for Python3
As per the problem statement I have solve the problem. Please let
me know if you have any doubts or you want me to modify the answer.
And if you find this answer useful then don't forget to rate my
answer as thumps up. Thank you! :)
Code:
//main.py
# Prompt user to enter the title for the dat user going to enter
and store
dataTitle = input("Please Enter a title for the data: ")
print("YUser entered:", dataTitle)
# Prompt user to enter the first column name
column1 = input("\nPlease Enter the column 1 header: ")
print("User entered:", column1)
# Prompt user to enter the second column name
column2 = input("\nPlease Enter the column 2 header: ")
print("User entered:", column2)
inputMessage = "\nEnter a data point (-1 to stop inserting data
and print the data): "
# Create data list
dataList = []
# While loop to enter the data continuously
while True:
# Prompt user to enter the data point
dataPoint = input(inputMessage)
if dataPoint != "-1":
if "," in
dataPoint:
# split method to split the data point in two
dataInfo = dataPoint.split(",")
if len(dataInfo) > 2:
print("Error: enter the correct from of datat.")
inputMessage = "\nPlease Enter a valid data point: "
elif not dataInfo[1].replace(" ", "").isdigit():
print("Error: Please enter the data in correct form.")
inputMessage = "\nEnter a valid data point: "
else:
# Output the stinf and integer from the data
print("Data string:", dataInfo[0])
print("Data integer:", dataInfo[1].replace(" ", ""))
inputMessage = "\nEnter a data point (-1 to stop inserting data and
print the data): "
# Add enter data point to the end of the list
dataList.extend(dataInfo)
elif "," not in
dataPoint:
print("Error: No comma in string.")
inputMessage = "\nEnter a valid data point: "
else:
break
# print the data title and the both column enter by the
user
print("\n%33s" % dataTitle)
print("%-20s|%23s" % (column1, column2))
print("-" * 44)
# iterate data throught the list
index = 0
while index < len(dataList):
print("%-20s|%23s" % (dataList[index],
dataList[index + 1]))
index += 2
# print the histogram of the data enter by the user
i = 0
print("")
# while loop to print the all the data points
while i < len(dataList):
print("%s %s" % (dataList[i], (int(dataList[i +
1]) * "*")))
i += 2
--------------------------------------------------------------------------------------------------------------------------------------------------
Program Code screenshot:
--------------------------------------------------------------------------------------------------------------------------------------------------
Program Output Screenshot: