(Using Python 2.5.4) When I run this code, "What is your name?" is asked two times. It asks "What is your name?", I input my name. Then it asks "What is your name?" again, I input my name again. Lastly it prints my name. How do I fix this so it only asks "What is your name?" one time? print(raw_input('What is your name?')) x=raw_input('What is your name?') print(x)
When you use the raw_input() function, whatever is in the () is used as a prompt. So your code is doing this: print(raw_input('What is your name?')) \(\leftarrow\) Display the prompt and take in stuff and pass it to the print function. x=raw_input('What is your name?') \(\leftarrow\) Display the prompt and take in stuff and assign it to x. print(x) \(\leftarrow\) print out x. So you are doing everythig twice.
mccormick is correct. You do not need the first print statement since here you are just asking the program to print that statement but it is doing nothing with the input. Your second line is all you need since here you are taking the raw input and assigning it to x and you have a prompt that will be printed asking for the input.
I believe I understand, thank you all.
Join our real-time social learning platform and learn together with your friends!