New line for input in Python

Question:

I am very new to Python programming (15 minutes) 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. I read about using n but when I tried:

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

It didn’t work.

Asked By: Atul_Madhugiri

||

Answers:

Put it inside of the quotes:

Number = raw_input("Enter a numbern")

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
""")
Answered By: Blender

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

print "Enter a number"
Number = raw_input()
Answered By: Oliver

In the python3 this is the following way to take input from user:

For the string:

s=input()

For the integer:

x=int(input())

Taking more than one integer value in the same line (like array):

a=list(map(int,input().split()))
Answered By: user17511

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()
Answered By: Savio Mathew

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!

Answered By: RetroWolf
# 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")

Answered By: yfalls
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.