-1

I wanted to write an input to receive a line of text, but it was valid when I typed the newline character directly, and ran the following code. Could the input read the newline character? But it doesn't match the information I found

message=input("please enter your name")
print("your name is",message)
  • 1
    your description is confusing, `it was valid when I typed the newline character directly, ` what was valid? also what didn't match and what information you found? – Devesh Kumar Singh Jun 26 '19 at 07:59
  • Thank you ,I mean the input receives it and continues to run the program,And what I found was that input doesn't read newline character – poem creay Jun 26 '19 at 08:08
  • If by _ran the following code_ you mean the `print("your name is",message)` is executed after you entered an empty line, then I can't reproduce that, and the behavior you encounter is indeed irregular. – Armali Jun 26 '19 at 08:18
  • Thank you very much ,This code is not what I thought, I have corrected it. – poem creay Jun 26 '19 at 08:33
  • What is the expected behaviour? Please elaborate in your question. – TrebledJ Jun 26 '19 at 08:40

1 Answers1

0

First of all, your answer will vary on the basis of the version of python you are using. If using python2.7, instead of 'input' you can use 'raw_input' to take the string as an input from the user. Also, I think you would prefer '+' instead of ',' in print function.

    message = raw_input("please enter your name\n")
    if message:
    print ("your name is"+ message)

If you are using python3 then you can simply add newline character.

    message = input("please enter your name\n")
    if message:
        print ("your name is", message)
Titan25
  • 1
  • 1