Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def main():
- english_spanish = {"hey": "hola", "home": "casa", "thanks": "gracias"}
- while True:
- print("Dictionary contents:")
- a_list = sorted(english_spanish)
- list = ", ".join(a_list)
- print(list)
- command = input("[W]ord/[A]dd/[R]emove/[P]rint/[T]ranslate/[Q]uit: ")
- if command == "W":
- word = input("Enter the word to be translated: ")
- if word in english_spanish:
- print(word, "in Spanish is", english_spanish[word])
- else:
- print("The word", word, "could not be found from the dictionary.")
- elif command == "A":
- word_english = input("Give the word to be added in English: ")
- word_spanish = input("Give the word to be added in Spanish: ")
- english_spanish[word_english] = word_spanish
- elif command == "R":
- word_remove = input("Give the word to be removed: ")
- if word_remove in english_spanish:
- del english_spanish[word_remove]
- else:
- print("The word", word_remove, "could not be found from the dictionary.")
- elif command == "Q":
- print("Adios!")
- return
- elif command == "P":
- for i in sorted(english_spanish):
- print(i, english_spanish[i])
- elif command == "T":
- sentence = (input("Enter the text to be translated into Spanish: "))
- sent = sentence.split()
- for word in sent:
- if word in english_spanish:
- sent[sent.index(word)] = english_spanish[word]
- print("The text, translated by the dictionary: ")
- print(" ".join(sent))
- else:
- print("Unknown command, enter W, A, R, P, T or Q!")
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement