Python Forum
Translating language in python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Translating language in python
#8
(Apr-01-2017, 10:13 PM)sparkz_alot Wrote: "requires me to use nested if-statements (not lists) in order to write a function".  I presume that means dictionary's as well :-).
 I was just about to comment that. It very confusing, i mean are "lists" considered "tuples"/"dictionaries"; Guess the context of the question is not really clear.

@
Quote:Liquid_Ocolet
if translate == "German":
   if words == "dog":
       print("The Translation of dog into German is 'hond'")
   elif words == "cat":
       print ("The translation of cat into German is 'katze'")
   else:
       print("I can not understand")
There is something not correct here, so the users input "GERMAN" language and is supposed to enter the words in "ENGLISH".

And converting it into a simple function


def trans(language, words):
    if language == "French":
        if words == "chien":
            print("English => Dog")
            print("Dutch => hond")
        elif words == "chat":
            print("English => Cat")
            print("Dutch => kat")
        else:
            print("I can not understand")
        # KEEP ADDING ELIF FOR ALL THE OTHER WORDS
    if language == "English":
        if words == "dog":
            print("French => chien")
            print("Dutch => hond")
        elif words == "cat":
            print("French => chat")
            print("Dutch => kat")
        # KEEP ADDING ELIF FOR ALL THE OTHER WORDS
        else:
            print("I can not understand")

language = raw_input("What do you want to translate to :")
words = raw_input("Please state the word :")
trans(language, words)
Reply


Messages In This Thread
Translating language in python - by Liquid_Ocelot - Apr-01-2017, 08:41 PM
RE: Translating language in python - by alicarlos13 - Apr-01-2017, 09:17 PM
RE: Translating language in python - by wavic - Apr-01-2017, 09:48 PM
RE: Translating language in python - by sparkz_alot - Apr-01-2017, 10:13 PM
RE: Translating language in python - by alicarlos13 - Apr-01-2017, 10:24 PM
RE: Translating language in python - by sparkz_alot - Apr-01-2017, 11:45 PM
RE: Translating language in python - by Skaperen - Apr-02-2017, 05:00 AM
RE: Translating language in python - by sparkz_alot - Apr-02-2017, 01:36 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  American Adolescent language in python. Deo 2 1,520 Feb-18-2022, 12:12 PM
Last Post: perfringo
  Translating orderflow into code reez0105 0 1,332 Nov-16-2019, 05:28 AM
Last Post: reez0105

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020