Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

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 »
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 e
or 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.
eak - Used to exit a for loop or a while loop.
continue - Used to skip the cu
ent block, and return to the "for" or "while" statement
dictionary - A mutable associative a
ay (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
E
or. Please enter an integer.
How many would you like to add? -4
E
or. Please enter a positive number.
How many would you like to add? one
E
or. Please enter an integer.
How many would you like to add? 2
Term #1:
eak
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.
eak - Used to exit a for loop or a while loop.
continue - Used to skip the cu
ent block, and return to the "for" or "while" statement
dictionary - A mutable associative a
ay (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
E
or. Please enter an integer.
How many would you like to add? -4
E
or. Please enter a positive number.
How many would you like to add? one
E
or. Please enter an integer.
How many would you like to add? 2
Term #1:
eak
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.
eak - Used to exit a loop
continue - Used to skip the cu
ent block, and return to the "for" or "while" statement
dictionary - A mutable associative a
ay (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

term    definition
stem    produce a stem and leaf plot
abline    draw a straight line
points    draw points on the cu
ent plot
print    print output
stripchart    produce a strip chart
sunflowerplot    produce a sunflower plot
qqline    add a line to a QQ plot
cor    calculate the Pearson co
elation coefficient

term    definition
eak    Used to exit a for loop or a while loop.
continue    Used to skip the cu
ent block, and return to the "for" or "while" statement
dictionary    A mutable associative a
ay (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.
Answered Same Day Feb 22, 2021

Solution

Sonu answered on Feb 22 2021
151 Votes
#!/us
in/env python
# coding: utf-8
# In[4]:
#checking whether entered number is a positive intege
def takeValidNumber():
while True:
try:
noOfTerms = int(input("How many would you like to add?"))
if noOfTerms < 0:
print("E
or: Please enter a positive number.")
else:
return noOfTerms
except:
print("E
or: 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("E
or: Please enter a valid response.")
addmore = input("Would you like to add more terms?(Y/N)")

return addmore
#taking input from file with e
or 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