Different outputs for almost same code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Different outputs for almost same code

If i write input("enter") then it asks for input but only shows 'enter' in output.Why? whereas if i write a=input("enter") print(a) then it asks for input and works good.

17th Jun 2019, 2:19 PM
DEVANSH BANSAL
DEVANSH BANSAL - avatar
5 Answers
+ 4
In the first case : U r asking the python interpreter to take the input but not assigning any variable to store the input value , so it takes the input and throws it away afterwards But in the second case: U have assigned a variable and later u have asked to print , hence u get the output
17th Jun 2019, 2:27 PM
Tony Stark
Tony Stark - avatar
+ 3
In the first example you're only asking for an input; in the second one you're specifying an output as well. INPUT: input("enter") or a = input("enter") OUTPUT: print(a) You can actually write it all in one go like this: print("Your input is: " + input()) This gives input as the parameter for print.
17th Jun 2019, 2:24 PM
Rincewind
Rincewind - avatar
+ 2
Python unlike other languages has input function which allows u to prompt any message to the user so u only get the prompt ("enter") in first case
17th Jun 2019, 2:30 PM
Tony Stark
Tony Stark - avatar
+ 1
What i am trying to say is that in the first example the output it shows is enter and nothing else
17th Jun 2019, 2:26 PM
DEVANSH BANSAL
DEVANSH BANSAL - avatar
+ 1
Thanks Tony 3000!
17th Jun 2019, 2:28 PM
DEVANSH BANSAL
DEVANSH BANSAL - avatar