6

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.

Remi Guan
  • 20,142
  • 17
  • 60
  • 81
Atul_Madhugiri
  • 89
  • 1
  • 1
  • 5

5 Answers5

24

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
""")
Blender
  • 275,078
  • 51
  • 420
  • 480
  • Thank you. I saw something like that but ignored it because in languages like C# whatever is in the quotes in printed exactly. Thanks anyways! This community seems really useful. – Atul_Madhugiri Dec 22 '11 at 05:17
2

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

print "Enter a number"
Number = raw_input()
Oliver
  • 24,606
  • 7
  • 65
  • 89
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!

RetroWolf
  • 11
  • 2
-2

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()
Savio Mathew
  • 637
  • 1
  • 7
  • 14
-3

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()))
Littlefoot
  • 107,599
  • 14
  • 32
  • 52