Python Write a program that creates a dictionary from a vocabulary list (formatted in a file similar to vocablist.txt and myvocab.txt). If the user-entered file name does not exist, the program...

1 answer below »
Please see the attached word file for specs.


Python Write a program that creates a dictionary from a vocabulary list (formatted in a file similar to vocablist.txt and myvocab.txt). If the user-entered file name does not exist, the program should catch the error and re-prompt for a file name. After the file is read in successfully, the program should use the "term" as the key and "definition" as the value. The program should then ask the user if he/she would like to add additional terms and definitions, and how many if "Y" is the response. If the user enters a negative non-integer value, the program will prompt the user again for an integer value. The program should then prompt the user for as many terms and definitions as needed. The program should ask again if the user would like to add additional terms and definitions. Again, the program will ask "how many" if "Y" is the response. The program should loop between asking if the user would like to add additional terms and definitions, and how many, until the user types "N" for No. If a duplicate term (key) is entered, the program will notify the user that the term is already in the dictionary. It will ask if the user would like to update the definition BEFORE asking for a definition. The program should end by printing the list of terms and definitions before asking the user for a file name to save the new dictionary. DO NOT SAVE OVER THE ORIGINAL TEXT FILE UNLESS ENTERED BY THE USER. You may assume that the file will be a .txt file (with text separated by tabs "\t"). Below, you will find examples of what the program might look like, with red as the user input: ##Example 1 Please enter a file name: vocablist.txt There are 10 terms in this vocabulary list. Would you like to add more terms (Y/N)? Y How many would you like to add? 2 Term #1: IDLE Definition #1: Integrated development environment Term #2: if Definition #2: Conditionally executes a block of code Would you like to add more terms (Y/N)? Y How many would you like to add? 0 Would you like to add more terms (Y/N)? N There are 12 terms in the new vocabulary list. break - Used to exit a for loop or a while loop. continue - Used to skip the current block, and return to the "for" or "while" statement dictionary - A mutable associative array (or dictionary) of key and value pairs. float - An immutable floating point number. immutable - Cannot be changed after its created. int - An immutable integer of unlimited magnitude. pass - Needed to create an empty code block set - Unordered set, contains no duplicates string - Can include numbers, letters, and various symbols and be enclosed by either double or single quotes while - Executes a block of code as long as its condition is true. IDLE - Integrated development environment if - Conditionally executes a block of code What would you like to save the file as? vocablist2.txt ##Example 2 Please enter a file name: vocablist.txt There are 10 terms in this vocabulary list. Would you like to add more (Y/N)? Y How many would you like to add? 1.5 Error. Please enter an integer. How many would you like to add? -4 Error. Please enter a positive number. How many would you like to add? one Error. Please enter an integer. How many would you like to add? 2 Term #1: break Warning! This term is already in the vocabulary list. Update definition (Y/N)? N Term #2: if Definition #2: Conditionally executes a block of code Would you like to add more terms (Y/N)? Y How many would you like to add? 0 Would you like to add more terms (Y/N)? N There are 11 terms in the new vocabulary list. break - Used to exit a for loop or a while loop. continue - Used to skip the current block, and return to the "for" or "while" statement dictionary - A mutable associative array (or dictionary) of key and value pairs. float - An immutable floating point number. immutable - Cannot be changed after its created. int - An immutable integer of unlimited magnitude. pass - Needed to create an empty code block set - Unordered set, contains no duplicates string - Can include numbers, letters, and various symbols and be enclosed by either double or single quotes while - Executes a block of code as long as its condition is true. if - Conditionally executes a block of code What would you like to save the file as? vocabulary.txt ##Example 3 Please enter a file name: vocablist.txt There are 10 terms in this vocabulary list. Would you like to add more (Y/N)? Y How many would you like to add? 1.5 Error. Please enter an integer. How many would you like to add? -4 Error. Please enter a positive number. How many would you like to add? one Error. Please enter an integer. How many would you like to add? 2 Term #1: break Warning! This term is already in the vocabulary list. Update definition (Y/N)? Y Definition #1: Used to exit a loop Term #2: if Definition #2: Conditionally executes a block of code Would you like to add more terms (Y/N)? Y How many would you like to add? 0 Would you like to add more terms (Y/N)? N There are 11 terms in the new vocabulary list. break - Used to exit a loop continue - Used to skip the current block, and return to the "for" or "while" statement dictionary - A mutable associative array (or dictionary) of key and value pairs. float - An immutable floating point number. immutable - Cannot be changed after its created. int - An immutable integer of unlimited magnitude. pass - Needed to create an empty code block set - Unordered set, contains no duplicates string - Can include numbers, letters, and various symbols and be enclosed by either double or single quotes while - Executes a block of code as long as its condition is true. if - Conditionally executes a block of code What would you like to save the file as? mynewvocablist.txt termdefinition stemproduce a stem and leaf plot ablinedraw a straight line pointsdraw points on the current plot printprint output stripchartproduce a strip chart sunflowerplotproduce a sunflower plot qqlineadd a line to a QQ plot corcalculate the Pearson correlation coefficient termdefinition breakUsed to exit a for loop or a while loop. continueUsed to skip the current block, and return to the "for" or "while" statement dictionaryA mutable associative array (or dictionary) of key and value pairs. floatAn immutable floating point number. immutableCannot be changed after its created. intAn immutable integer of unlimited magnitude. passNeeded to create an empty code block setUnordered set, contains no duplicates stringCan include numbers, letters, and various symbols and be enclosed by either double or single quotes whileExecutes a block of code as long as its condition is true.
Answered Same DayFeb 22, 2021

Answer To: Python Write a program that creates a dictionary from a vocabulary list (formatted in a file similar...

Sonu answered on Feb 22 2021
149 Votes
#!/usr/bin/env python
# coding: utf-8
# In[4]:
#checking whether entered number is a positive int
eger
def takeValidNumber():
while True:
try:
noOfTerms = int(input("How many would you like to add?"))
if noOfTerms < 0:
print("Error: Please enter a positive number.")
else:
return noOfTerms
except:
print("Error: Please enter an integer.")

return 0
#checking whether entered value belong to Y or N
def validYN(addmore):
while addmore != "Y" and addmore != "N":
print("Error: Please enter a valid response.")
addmore = input("Would you like to add more terms?(Y/N)")

return addmore
#taking input from file with error checking
def takeFileInput():
try:
file = input("Please enter file name: ")
vocabFile = open(file,'r');
vocabDict = {}
for l in...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here