How do I use raw_input( )?


#1

Question

How do I use raw_input( )?

Answer

raw_input() is a method that prints what you put inside to the console, waits for the user to type something, and returns whatever they typed after the enter key is pressed. This is a common mistake:

raw_input(“Enter something here: “)
my_variable = raw_input()

This doesn’t work because raw_input() is a method, so it’s simply going to use it each time you write it. By writing it by itself on the first line above, it just performs the method and moves on in the program to the next line without having assigned that value anywhere. Then on the second line, it runs raw_input() again, but with no prompt, so the user is just met with a blinking cursor and won’t know they’re being prompted for input.

The instructions show a great example of using this method properly to store the user’s input into a variable: name = raw_input("What's your name?").


FAQ: Learn Python - Pyglatin - Input!
#2

NOTE: We’re using Python 3.0, so that you should type code like this:

car = input(“Type your are name: “)
print (“car”)

if you will type “Lambo” in Type your car name the result will be:

Lambo


#3

not really? You print string car, not the variable (which contains value entered by user)

but its indeed true, the input functions changed in python3


#4

This is still a little confusing to me. What’s the point of having the program take input twice if only the one with the variable matters anyways? Is this answer saying the second line with the variable must have a “prompt” for raw input? If that’s the case then why isn’t the solution to the program simply

original = raw_input("Enter something here: ")

Why are we told to do the first raw_input(“Enter something here:”) if it doesn’t matter in terms of saving the input results as a variable. Why not just have one line of code to ask for the input and save it as a variable from beginning?


#5

or even:

print "enter something here: "
my_variable = raw_input()

if you want the user to type below.

Don’t overthink it, the FAQ feature is still work in progress, its fine as long as you understand what raw_input does


#6

Something odd is happening with the piglatin exercises . I put in the correct code and it just keeps on giving an ‘X’ in the instruction pains

I even copy the solutions code and re-enter it and that still comes out as an error


#7

Could be a glitch, it happened before. Can you continue by getting the solution until its fixed?


#8

No problem. i will carry on