Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
New Line Problem!
#1
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!
Reply
#2
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
Reply
#3
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='')
Reply
#4
(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.
Reply
#5
(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!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  problem with spliting line in print akbarza 3 335 Jan-23-2024, 04:11 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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