Python Forum

Full Version: New Line Problem!
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm trying to write a program that allows you to input a string of words, and then it translates them into my own custom language. I didn't get far before i realized that there was a serious problem where the code printed the results.
def lettertranslation():
    letter=input("Enter a letter, or type 'quit', to exit:")
    letter_list = list(letter)
    for letter_list in letter:

        if "a" in letter_list:
            print ("ba")
        elif "b" in letter_list:
            print ("ru")
        elif "c" in letter_list:
            print ("no")
        elif "d" in letter_list:
            print ("de")
        elif "e" in letter_list:
            print ("fi")
        elif "f" in letter_list:
            print ("ne")
lettertranslation()


Please tell me how to get the translation all on the same line!
print() takes optional argument end which by default is '\n'
Other option is to collect all "translated" letters in a list and then print it at once
if I may add:
letter_list
variable can also be commented out. what you're looking for as the previous op suggested is
print('a',end='')
(Feb-09-2018, 07:11 PM)mepyyeti Wrote: [ -> ]If I may add letter_list variable can also be commented out.
I intentionally left that part without comment, because it's correct thing to do. The opposite is true for this huge if/elif block.
A dictionary, or str.translate() method can be used.
(Feb-09-2018, 02:46 PM)buran Wrote: [ -> ]print() takes optional argument end which by default is '\n' Other option is to collect all "translated" letters in a list and then print it at once
thank you!