Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
397
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.86 KB | None | 0 0
  1.  
  2. def main():
  3.     english_spanish = {"hey": "hola",  "home": "casa", "thanks": "gracias"}
  4.  
  5.     while True:
  6.         print("Dictionary contents:")
  7.         a_list = sorted(english_spanish)
  8.         list = ", ".join(a_list)
  9.         print(list)
  10.         command = input("[W]ord/[A]dd/[R]emove/[P]rint/[T]ranslate/[Q]uit: ")
  11.  
  12.         if command == "W":
  13.  
  14.             word = input("Enter the word to be translated: ")
  15.             if word in english_spanish:
  16.                 print(word, "in Spanish is", english_spanish[word])
  17.             else:
  18.                 print("The word", word, "could not be found from the dictionary.")
  19.  
  20.         elif command == "A":
  21.             word_english = input("Give the word to be added in English: ")
  22.             word_spanish = input("Give the word to be added in Spanish: ")
  23.             english_spanish[word_english] = word_spanish
  24.  
  25.  
  26.  
  27.         elif command == "R":
  28.                 word_remove = input("Give the word to be removed: ")
  29.                 if word_remove in english_spanish:
  30.                     del english_spanish[word_remove]
  31.                 else:
  32.                     print("The word", word_remove, "could not be found from the dictionary.")
  33.  
  34.  
  35.         elif command == "Q":
  36.             print("Adios!")
  37.             return
  38.  
  39.         elif command == "P":
  40.             for i in sorted(english_spanish):
  41.                 print(i, english_spanish[i])
  42.  
  43.         elif command == "T":
  44.             sentence = (input("Enter the text to be translated into Spanish: "))
  45.             sent = sentence.split()
  46.             for word in sent:
  47.                 if word in english_spanish:
  48.                     sent[sent.index(word)] = english_spanish[word]
  49.             print("The text, translated by the dictionary: ")
  50.             print(" ".join(sent))
  51.  
  52.  
  53.  
  54.  
  55.         else:
  56.             print("Unknown command, enter W, A, R, P, T or Q!")
  57.  
  58.  
  59. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement