Reputation: 129
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.
Upvotes: 10
Views: 143427
Reputation: 1
# 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")
Upvotes: 0
Reputation: 11
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!
Upvotes: 1
Reputation: 787
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()
Upvotes: -3
Reputation: 298582
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
""")
Upvotes: 26
Reputation: 29621
If you want the input to be on its own line then you could also just
print "Enter a number"
Number = raw_input()
Upvotes: 2