8

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
  • 21,506
  • 17
  • 64
  • 87
Atul_Madhugiri
  • 109
  • 1
  • 1
  • 5

7 Answers7

25

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
  • 289,723
  • 53
  • 439
  • 496
  • 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
  • 27,510
  • 9
  • 72
  • 103
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
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")

Julia Meshcheryakova
  • 3,162
  • 3
  • 22
  • 42
yfalls
  • 1
  • 3
0

Try the code below

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

Opportunities: Line1: \n needs to be within the "" Line2: variable should be within the ()

-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
  • 719
  • 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
  • 131,892
  • 15
  • 35
  • 57