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
What is computer? Explain the characteristics of computer.<br>​
Misha Larkins [42]

Answer:

What Is Computer? Here's Why: The characteristics of computers that have made them so powerful and universally useful are speed, accuracy, diligence, versatility and storage capacity. Let us discuss them briefly. Computers work at an incredible speed. A powerful computer is capable of performing about 3-4 million simple instructions per second.

Explanation:

6 0
3 years ago
Organizations following Waterfall methodology usually begin with requirements gathering, in which the development team attempts
Aleks04 [339]

Answer:

Project teams do smaller portions of the entire project in small sprints.

Teams can interact to handle different steps simultaneously if needed.

Documentation is still required to keep everybody on track. This documentation allows teams to keep control over what version of the project they are working on and how the project has changed along the way.

As an approach to rapid development, the focus is on development rather than planning, enabling teams to start work more quickly.

hope this helps you

:)

7 0
3 years ago
Which windows tools would you use to browse the files system on a hard drive?
otez555 [7]

<span>The answer is Windows Explorer and My Computer. Windows compromises two methods to see its file system. Either program permits you to browse and edit the files and folders on your computer. Normally, My Computer is easier for novices to comprehend. It will open one folder at a time and show you its contents. </span>

6 0
3 years ago
Read 2 more answers
Meaning of ‘integrity of data’
Makovka662 [10]

Answer: i have no idea

Explanation:

6 0
3 years ago
Read 2 more answers
If two egg cells are fertilized what will happen?
Orlov [11]
Just try it and see what will happen
3 0
3 years ago
Other questions:
  • Do you believe that OOP should be phased out and we should start working on some alternative
    6·1 answer
  • Which of the following best describes the 7x7 PowerPoint rule
    8·1 answer
  • --------------------is a host that runs software to provide information, such as web content, to other hosts.
    9·1 answer
  • write a program that reads in the length and the width of a rectangular yard . your program should compute the time required ( i
    5·1 answer
  • In Java
    6·1 answer
  • You just bought a hard drive, you plan on using this a secondary storage, once installed, what needs to be done to the drive and
    6·1 answer
  • During which phase of the website transformation processwould the project team for developing perform content analysis, layout t
    13·1 answer
  • Q: If a program is invoked with "python program.py -r input.dat output.dat", what are the elements of argv?
    10·1 answer
  • What Microsoft feature enables you to represent text as colorful visuals
    12·1 answer
  • Which statement is true about the energy of electromagnetic radiation?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!