Project Description
Create a program where users can add a word and the translation for that word through a command line interface. The program saves the results in a CSV file. This could be useful for someone who is learning new words in a foreign language and wants to create a vocabulary.
How the Project Works
(1) The program prompts the user to enter a word. The user enters “desk” and presses Enter. (2) The program prompts the user to enter a translation for that word in a foreign language. (3) The program repeats the process by prompting the user to enter another word. (4) If the user enters “done”, the program closes and adds the data to a CSV file*.
*Here is how the generated CSV file would look like:
Project Skills Needed
This project covers the following concepts. Click any link to learn more about them if you're unfamiliar.
input() function | print() function | strings |lists|
dictionaries | if-else conditionals | while-loops
Prerequisites
Required Libraries: csv (standard library - no need to install)
Required Files: No files are required.
IDE: You can use any IDE on your computer to code the project.
Danger Zone
Once you code the project, compare it with our solution below:
import csv
fieldname=['Language1','Language2']
with open(r"C:\Users\kulde\Downloads\example1.csv",'a',newline='') as file :
writer=csv.DictWriter(file,fieldnames=fieldname,)
writer.writeheader()
while True:
org_word=input("Enter a word in languahe 1(or type 'done' to finish):")
if org_word.lower() == 'done':
break
else:
trans=input('enter the translation of {} in the language2 :'.format(org_word))
writer.writerow({'Language1':org_word,
'Language2':trans})
print('{}(language1) has been added with the translation : {} (language2)'.format(org_word,trans) )
This was good one!! Enjoyed the learning..thanks