python - How can I print the entire converted sentence on a single line? -


i trying expand on codeacademy's pig latin converter practice basic programming concepts.

i believe have logic right (i'm sure it's not concise be!) , trying output converted pig latin sentence entered user on single line.

if print inside loop prints on new lines each time. if print outside prints first word not iterating through words.

could please advise going wrong?

many, many help.

pyg = 'ay'  print ("welcome matt's pig latin converter!")  def convert(original):     while true:         if len(original) > 0 , (original.isalpha() or " " in original):             print "you entered \"%s\"." % original             split_list = original.split()              word in split_list:                 first = word[0]                 new_sentence = word[1:] + first + pyg                 final_sentence = "".join(new_sentence)                 print final_sentence               break          else:             print ("that's not valid input. please try again.")             return convert(raw_input("please enter word: "))  convert(raw_input("please enter word: ")) 

try:

pyg = 'ay'  print ("welcome matt's pig latin converter!")  def convert(original):     while true:         if len(original) > 0 , (original.isalpha() or " " in original):             final_sentence = ""             print "you entered \"%s\"." % original             split_list = original.split()             word in split_list:             first = word[0]             new_sentence = word[1:] + first + pyg             final_sentence = final_sentence.append(new_sentence)             print final_sentence                break          else:             print ("that's not valid input. please try again.")             return convert(raw_input("please enter word: "))  convert(raw_input("please enter word: ")) 

it's because remaking final_sentence every time in loop instead of adding it.


Comments

Popular posts from this blog

serialization - Convert Any type in scala to Array[Byte] and back -

matplotlib support failed in PyCharm on OSX -

python - Matplotlib: TypeError: 'AxesSubplot' object is not callable -