Python Forum
New Line Problem! - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: New Line Problem! (/thread-8203.html)



New Line Problem! - digitalMASTER1 - Feb-09-2018

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!


RE: New Line Problem! - buran - Feb-09-2018

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


RE: New Line Problem! - mepyyeti - Feb-09-2018

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='')



RE: New Line Problem! - buran - Feb-09-2018

(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.


RE: New Line Problem! - digitalMASTER1 - Feb-09-2018

(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!