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
I'm 11, except my profile says I'm 15.
aleksandr82 [10.1K]

Answer:

Hello there, I dont think there is a way to change you age, but maybe you shall try again tomorrow and see if an error message pop up.  If the Error Message pops up, contact custumaor support!

Glad I could Help!

3 0
3 years ago
Write a program to test the various operations of the class clockType
Umnica [9.8K]
The class clock type was designed to implement the time of day in a program. Certain applications, and additions to hours, minutes, and seconds, might require you to start at the time zone.
5 0
3 years ago
Which type of address is the ip address 232. 111. 255. 250?.
svp [43]
I think it’s a multicast
8 0
2 years ago
Password procedures, information encryption software, and firewalls are examples of measures taken to address:
Gnoma [55]
<span>Password procedures, information encryption software, and firewalls are examples of measures taken to address are all measures taken to safeguard information security and protect users data from being tampered or manipulated by invaders. 

In web, if we leave our information without encryption or if we leave our system without firewall, different types of security threats might arise: such as, information being hacked, manipulated or sent to wrong places. To avoid this information encryption is done. We might also need to firewall our system so that we can avoid unwanted access and invading of our privacy using malwares and other tools. </span>
5 0
3 years ago
Um?<br><br> i went to check my questions and i found this-
asambeis [7]

Answer:

just go ahead and refresh the page

Explanation:

5 0
2 years ago
Other questions:
  • Header and Footer options are located in the _____ tab.
    7·1 answer
  • A Windows user has been successfully saving documents to the file server all morning. However, the latest attempt resulted in th
    9·2 answers
  • True or False: <br> The object reference can be used to polymorphically store any class in Java.
    13·1 answer
  • -Which of the following is true about Web services?
    10·1 answer
  • What is Naptha used for?
    9·2 answers
  • Your organization uses a type of cryptography that provides good security but uses smaller key sizes and utilizes logarithms tha
    9·1 answer
  • How to create a network of relevant prospects?
    5·1 answer
  • HELP ASAP Encoding a video format and then decoding it during playback is one of the functions of MPEG-4 and H.264 file players.
    10·2 answers
  • Which panel is used to make a website​
    8·1 answer
  • Direction: Write True on the line if the statement is correct. Write False if the statement is incorrect. 1. All objects are com
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!