0

I'm a little new to python and I'm trying to fill raw_input with a formatted string yet my output never changes the "\n" character and always returns null. Is there a way to pump fully formatted string/text through an empty variable?

text = ""
stop = "|"


while True:
   text_1 = raw_input()
   text += "%s" % (text1)
   if text_1 != stop:
     pass
   else:
     break


print text

output:
hello world
how are you
|
hello worldhow are you|

need: hello world how are you |

shadowspawn
  • 1,616
  • 17
  • 20
Aze
  • 79
  • 3

1 Answers1

0

I'm confused at what you mean by "fully formatted text". I'm also confused at what you mean by "returns null".

raw_input returns the string that was read, which might be an empty string, but should never be None. By the way, if you are familiar with NULL in C-like languages, None is sort of the equivalent in Python.

This piece of code is close to yours and has what I believe is your desired behavior.

text = ""
stop = "|"


while True:
  text_1 = raw_input()
  if text_1 != stop:
    text += text_1 + " "
  else:
    text += text_1
    break

print text
Enrico Borba
  • 1,467
  • 2
  • 11
  • 20