vastdd.blogg.se

Piglatin translator
Piglatin translator








piglatin translator

  • You don't have to enter an if statement to set a Boolean variable just set it to the thing in the if.
  • "the" gets translated to "hetay" (not actual piglatin).
  • Why does the main method return True? If anything (which it shouldn't, having a name like main), it should return the translated list.
  • Try making a Boolean that keeps track of the user has inputed a correct value, and put the entire input sequence in a while loop.
  • Repeated calls to main can eventually overflow the stack trace (heh, stackoverflow).
  • That is the standard for main methods, so if you, at a later date, decide to import you code from another file, the main method will not run and you can still use the translation functions. The main method should be in something like this: (more pythonic) if _name_ = "_main_": Just put it inside the call to input on the next line.Ĭhange list_word to word_list. Words may consist of alphabetic characters only (A-Z and a-z). For anybody who doesn't know the Pig Latin, feel free to look at the README, which explains what Pig.

    Piglatin translator how to#

    I would really appreciate it if anybody could give suggestions of how to improve the code and make the program more efficient. Note that hyphenated words are treated as two words. Over the last few days I created this Pig Latin Translator just for fun. This is accomplished via this HTML document and accompanying JavaScript program.

    piglatin translator

    Speaking of lang, it doesn't look like you need it. English to Pig Latin Translator Enter English Text to Translate: Enter the English text here that you want translated into Pig Latin. You may also want to change the name of the function because it doesn't convey much meaning when calling it like that. Pass # or time.sleep(1) like you did, but it feels a bit unresponsive This let you handle retries outside of the function: while not main(): Translated_sentence = ' '.join(translate(word) for word in sentence.split()) Print("Invalid input, please do not use numbers or punctuation marks") Question = "Enter a sentence to translate it into : ".format(lang)) To_piglatin = ("e", "p").index(to_piglatin.lower()) To_piglatin = input("Do you want to translate something to piglatin, or to english: ") I would just like it if someone reviewed my code and see if anything can be done to make it more Pythonic or efficient. I am a relatively new Python programmer and made a simple Pig Latin to English translator and vice versa.










    Piglatin translator