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]
2 years ago
15

CS160 Computer Science I In class Lab 10

Computers and Technology
1 answer:
lianna [129]2 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
How does culture affect your life
777dan777 [17]
Culture identifies who you are, what you value, and how you act. 
5 0
3 years ago
What does the following function return? void index_of_smallest(const double all, int startindex, int numberOfSlots); A. a doubl
Flauer [41]

Answer:

nothing

Explanation:

Because the return type of the function is void. void means does not return any thing.

The syntax of the function:

type name( argument_1, argument_2,......)

{

  statement;

}

in the declaration the type define the return type of the function.

it can be int, float, double, char, void etc.

For example:

int count( int index);

the return type of above function is int. So, it return integer.

similarly,

void count(int index);

it return type is void. So, it does not return any thing.

7 0
3 years ago
What is the best application to create a slide show presentation?
Lynna [10]

Answer:

Microsoft Windows File Manager

5 0
3 years ago
Read 2 more answers
What type of graphic organizer will help jane compare the results of a student survey about teachers at her school?
Olin [163]
For me its chart graph because you're able to visualize the given numbers and its not confusing
5 0
3 years ago
Read 2 more answers
Music = ("rap", "hip hop", "gospel")
astraxan [27]
Music = (“rap”, “hip hop”, “gospel”)
Country = (“country”,) #make sure that comma is outside of quotes
New_music = music + Country
print(New_music)
#var can be whatever you want
output:
(“rap”, “hip hop”, “gospel”, “country”)
4 0
2 years ago
Other questions:
  • Several coworkers in the sales department received an email claiming to be from you. Each message was personally addressed and c
    11·1 answer
  • The _________ contains frequently used formatting commands that are displayed when selecting text or objects with the mouse.
    7·1 answer
  • Suppose that you created an robot that was so advanced it could act independently in very complex situations. It made its own de
    9·1 answer
  • Explain how to identify a starting position on a line.
    15·2 answers
  • Budgets help you to do all of the following expect
    15·2 answers
  • Intellectual ______ is the legal term for ownership of intangible assets such as ideas, art, music, movies, and software.
    13·2 answers
  • Which of the these is tool for creating mobile apps? A:C# B:Apple Pie C:Appy Pie D:C++​
    8·2 answers
  • Code works, need help writing header file.
    8·1 answer
  • Horizontal and vertical scaling usually refer to increasing the capacity of
    6·1 answer
  • Which statement best describes the problem statement below?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!