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 usually happens at a police check? Do they just look up your name in their system?
sdas [7]

it depends on the kind of police check. like if its a road block type of check, they make sure everything is right. if you get pulled over you get your name ran in the system to check if you have warrents or warning and depends on what you get pulled over for, you could get a ticket or detained.

5 0
4 years ago
What are the disadvantages of using pointers?
garik1379 [7]

Explanation:

The pointer is the variable that will store the address of the other variable of the same datatype.

Following are the disadvantages of using a pointer.

1. Pointer sometimes causes a segmentation fault in the program.

2. Sometimes pointer leads to a memory leak.

3. A pointer variable is slower than normal variable.

4. Sometimes the program is crash if we using pointer because sufficient memory is not allocated during runtime.

5. If we using pointer it is difficult to find the error in the program.

5 0
3 years ago
Send a newsletter when you want to communicate directions, advice, or information.
lilavasa [31]
True, since you do want to give out information
4 0
3 years ago
Read 2 more answers
Answer the following questions:
Alika [10]

Answer:

nasaan po yung tanongkkkkk

8 0
3 years ago
Developed by ibm and refined by symantec, the __________ provides a malware detection system that will automatically capture, an
Nadya [2.5K]
Digital Immune System (DIS)
6 0
3 years ago
Other questions:
  • The ________________ command ends the current command session
    12·2 answers
  • Provide an example of a question that could NOT be answered with a binary message. Explain why this is the case, making referenc
    7·1 answer
  • What protocol runs on port 23?!?!
    11·2 answers
  • 1. Write a program that uses String method regionMatches to compare two strings input by the user. The program should prompt the
    8·1 answer
  • Is the practice of downloading and distributing copyrighted content digitally without permission??
    14·1 answer
  • What is the biggest danger when you reveal information such as your Social Security number?
    15·2 answers
  • I need help ASP 3rd grade math ​
    11·2 answers
  • Why do we use if statements?
    9·1 answer
  • consider l= 5 ,r= 11. you must determine the sum of the values of the function in the range L to R . you have to calculate sum =
    7·1 answer
  • I need help with excel
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!