11

I wanted to make a simple program that would take an input and then print it back out. This is how my code looks:

Number = raw_input("Enter a number")
print Number

How can I make it so a new line follows the prompt? I read about using \n, but when I tried:

Number = raw_input("Enter a number")\n
print Number

it didn't work.

0

5 Answers 5

26

Put it inside of the quotes:

Number = raw_input("Enter a number\n")

\n is a control character, sort of like a key on the keyboard that you cannot press.


You could also use triple quotes and make a multi-line string:

Number = raw_input("""Enter a number
""")
Sign up to request clarification or add additional context in comments.

Comments

2

If you want the input to be on its own line then you could also just

print "Enter a number"
Number = raw_input()

Comments

1

I do this:

    print("What is your name?")
    name = input("")
    print("Hello" , name + "!")

So when I run it and type Bob the whole thing would look like:

What is your name?

Bob

Hello Bob!

Comments

0
# use the print function to ask the question:
print("What is your name?")
# assign the variable name to the input function. It will show in a new line. 
your_name = input("")
# repeat for any other variables as needed

It will also work with: your_name = input("What is your name?\n")

1 Comment

Welcome on SO! Please explain advantage of your solution, (And maybe how it work)
-3

in python 3:

#!/usr/bin/python3.7
'''
Read list of numbers and print it
'''
def enter_num():
    i = input("Enter the numbers \n")
    for a in range(len(i)): 
        print i[a]    
    
if __name__ == "__main__":
    enter_num()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.