1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Wittaler [7]
3 years ago
15

CS160 Computer Science I In class Lab 10

Computers and Technology
1 answer:
lianna [129]3 years ago
5 0

Answer:

The program in Python is as follows:

fname = input("Enter the translation file name: ")

with open(fname) as file_in:

   lines = []

   for line in file_in:

       lines.append(line.rstrip('\n'))

myDict = {}

for i in range(len(lines)):

x = lines[i].split(":")

myDict[x[0].lower()] = x[1].lower()

print("Enter an English word to receive the Spanish translation.\nPress ENTER to quit.")

word = input("Enter an English word: ")

while(True):

if not word:

 break

if word.lower() in myDict:

 print("The Spanish word is ",myDict[word.lower()])

else:  

 print("I don’t have that word in my list.")

word = input("Enter an English word: ")

Explanation:

This prompts the user for file name

fname = input("Enter the translation file name: ")

This opens the file for read operation

with open(fname) as file_in:

This creates an empty list

   lines = []

This reads through the lines of the file

   for line in file_in:

This appends each line as an element of the list

       lines.append(line.rstrip('\n'))

This creates an empty dictionaty

myDict = {}

This iterates through the list

for i in range(len(lines)):

This splits each list element by :

x = lines[i].split(":")

This populates the dictionary with the list elements

myDict[x[0].lower()] = x[1].lower()

This prints an instruction on how to use the program

print("Enter an English word to receive the Spanish translation.\nPress ENTER to quit.")

This prompts the user for an English word

word = input("Enter an English word: ")

This loop is repeated until the user presses the ENTER key

while(True):

If user presses the ENTER key

if not word:

The loop is exited

 break

If otherwise, this checks if the word exists in the dictionary

if word.lower() in myDict:

If yes, this prints the Spanish translation

 print("The Spanish word is ",myDict[word.lower()])

If otherwise,

else:

Print word does not exist

 print("I don’t have that word in my list.")

Prompt the user for another word

word = input("Enter an English word: ")

You might be interested in
A __________is a software program that appears to be a physical computer and executes programs as if it were a physical computer
svlad2 [7]

Answer:

Virtual Machine

Explanation:

<em> I had to look this up, since there were no options from the question. If this is wrong, let me know!</em>

8 0
2 years ago
Gps receivers are commonly used by individuals to determine their geographic location while hiking and to obtain driving directi
soldier1979 [14.2K]
I think it is true also.
7 0
3 years ago
What is mark in in premiere pro
Studentka2010 [4]
Markers are an often underutilized tool in the Premiere Pro CC toolbox. They are little colored tabs you can apply to both your timeline and your source clips to indicate important points in time with a color or note.
5 0
3 years ago
which midi keyboard mode allows for one sound on one end of the keyboard and another on the other end
wlad13 [49]

Answer:

Sound button in the scratch

5 0
3 years ago
What file name would allow you to easily find and edit your document later in Word Online?
DIA [1.3K]
The first one “ jane_essay 2_24_21 “
6 0
3 years ago
Read 2 more answers
Other questions:
  • A software program that allows a programmer to type in code. modern versions usually make it easy to format the code on the scre
    13·1 answer
  • Jenny is working on a laptop computer and notices that the computer is not running very fast. She looks and realizes that the la
    15·2 answers
  • A) A cable that is mainly used in the cable television network
    11·1 answer
  • Which of the following actions is an example of "window dressing?" a. Using some of the firm’s cash to reduce long-term debt. b.
    13·1 answer
  • Please create C program, the task is to implement a function edoublepowerx that has an input parameter x of floating-point value
    11·1 answer
  • Which of the following allows data to coordinate activity between devices? Select one: a. Address bus b. Collisions c. Data bus
    10·1 answer
  • Explain how the CPU processes data instructions.
    6·1 answer
  • describe how sodium ammonium chloride can be separated from a solid mixture of ammonium chloride and anhydrous calcium chloride​
    15·1 answer
  • Draw truth table for the following logic circuit:<br><br> (Please I really need help with this)
    15·1 answer
  • What does the following code print? time_of_day = ["morning", "afternoon", "evening"] for word in time_of_day: print "Good " + w
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!