+ 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?
2 Antworten
+ 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
0
please ensure array and parameters u have given to condition