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
""")
Answer from Blender on Stack OverflowPut 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
""")
If you want the input to be on its own line then you could also just
print "Enter a number"
Number = raw_input()
python - How to make text from user input start a new line at every space? - Stack Overflow
Accepting input till newline in python - Stack Overflow
how to go to a new line after getting an input in python? - Stack Overflow
How would I make the output make a new line after each output?
Videos
Probably the slickest way that I know (with no error handling, unfortunately, which is why you don't see it too often in production):
>>> lines = list(iter(input, ''))
abc
def
.
g
>>> lines
['abc', 'def', '.', 'g']
This uses the two-parameter call signature for iter, which calls the first argument (input) until it returns the second argument (here '', the empty string).
Your way's not too bad, although it's more often seen under the variation
a = []
while True:
b = input("->")
if not b:
break
a.append(b)
Actually, use of break and continue is one of the rare cases where many people do a one-line if, e.g.
a = []
while True:
b = input("->")
if not b: break
a.append(b)
although this is Officially Frowned Upon(tm).
Your approach is mostly fine. You could write it like this:
a = []
prompt = "-> "
line = input(prompt)
while line:
a.append(int(line))
line = input(prompt)
print(a)
NB: I have not included any error handling.
As to your other question(s):
raw_input()should work similarly in Python 2.7int()-- Coerves the given argument to an integer. It will fail with aTypeErrorif it can't.
For a Python 2.x version just swap input() for raw_input().
Just for the sake of education purposes, you could also write it in a Functional Style like this:
def read_input(prompt):
x = input(prompt)
while x:
yield x
x = input(prompt)
xs = list(map(int, read_input("-> ")))
print(xs)
You don't want the newline in the prompt. You want it after the input has been read. Try this:
name=input("name :")
print()
print(name)
"... I just wanna get an input and go to a new line after that ..."
Here is an example
print('\n' + (name := input("name :")))
Output
name :abc
abc