why the first variable input notice is printed if the variable is reassigned after? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

why the first variable input notice is printed if the variable is reassigned after?

foo = input("Enter a number: ") foo = "pepper" print(foo) if you run this code and enter anything, then there will be printed: enter a number: pepper. why this text from input is printed anyway independently to reassigned variable?

18th Jul 2016, 5:09 AM
Jim Beam
Jim Beam - avatar
2 Answers
+ 2
the parameter to the input command is just an information for the user who enters information(in this case instruction that number needs to be entered). code playground behaves a little different then the actual console so it's hard to see what's actually happening. if you run your program on computer you will get the following: 1. "Enter a number: " with the blikning cursor waiting for user input 2. user inputs the number and presses enter 3. "pepper" is then printed assignment of "pepper" to variable foo is done after the input, so it can't affect input statement
18th Jul 2016, 7:33 AM
RedAnt
RedAnt - avatar
0
please ensure array and parameters u have given to condition
20th Jul 2016, 8:14 AM
Mohan pochampalle
Mohan pochampalle - avatar