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
While you are working on your computer, it shuts down unexpectedly, and you detect a burning smell. When you remove the case cov
kumpel [21]

Answer:

fire

Explanation:

hydrant

6 0
3 years ago
Which of the following is the result of a query?
IgorLugansk [536]
I think the answer is A
6 0
2 years ago
Which two statements about using leased lines for your wan infrastructure are true? (?
Karo-lina-s [1.5K]
<span>The following statements are true: 1. Leased lines require little installation and maintenance expertise. ( A high service quality is offered by point-to point system) 2. Leased lines provide highly flexible bandwidth scaling. (This Allows a Constant availability)</span>
7 0
3 years ago
1) APPLICATION BASED QUESTION:-
schepotkina [342]

Answer:

Photoshop

Explanation:

8 0
2 years ago
PP 11.1 – Write a program that creates an exception class called StringTooLongException, designed to be thrown when a string is
Scrat [10]

Answer

The answer and procedures of the exercise are attached in the following archives.

Step-by-step explanation:

You will find the procedures, formulas or necessary explanations in the archive attached below. If you have any question ask and I will aclare your doubts kindly.  

6 0
3 years ago
Other questions:
  • In Windows 7/Vista, the information that establishes basic settings such as the location of the operating system and other key s
    7·1 answer
  • Which speaker port should you use when connecting a single speaker to a pc?
    6·1 answer
  • 3. What term refers to the physical locations of elements in relation to each other?
    10·2 answers
  • For this lab, you will work on a simple GUI application. The starting point for your work consists of four files (TextCollage, D
    5·1 answer
  • Loops are frequently used to ____; that is, to make sure it is meaningful and useful.
    12·1 answer
  • because of online writing, our audience: A. Compromise older people B. are bigger than before C. usually read less often D. are
    15·2 answers
  • To give your app users the ability to open your app directly from other apps by clicking a link, you should use:.
    11·1 answer
  • CODEHS- Please help!
    8·1 answer
  • Compare mini and mainframe computer in terms of speed,memory and storage​
    15·1 answer
  • The ________ function will change a character argument from lowercase to uppercase. isupper toupper tolarge fromlower none of th
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!