+ 1
Hi guys! Please, does anyone knows the difference between INPUT and PRINT?
For example: I tried the following code: Input('\n smile') Output: smile Traceback (most recent call last): File "./Playground/file0.py", line 2, in <module> input('\n smile') EOFError: EOF when reading a line BUT If I use: print('\n smile') Output: smile What is happening? Why the first one shows an Error and the sencond doesn't not? Thanks
17 Respuestas
+ 4
You use "print()" when you want to print something to the console. You use "input()" when you want to take an input of some data from the user of your program. That is the difference.
The string inside the brackets for input() is the prompt the user will see when the program runs. In the SoloLearn code playground, the prompt is shown on the console, and that is why you are able to see it. However, you won't see what the user input is unless you print it. To see what I mean, try this code:
word = input("Enter a word:\n")
print(word)
When the code playground prompts you for an input, enter any word you like.
+ 3
Input asks for the user's input, and in Playground here, you need to separate between each input by jumping to a new line when the input is requested. For the Print, it displays an interger, a string, etc...
+ 3
Python is case-sensitive, so it needs to be "input" rather than "Input" for it to work. Python will see "Input" as something different to "input" and give a NameError because "Input" has not been defined in the code.
+ 3
The EOFError happens when your program is expecting something, but the something is not found, so your program ends prematurely. In the case of inputs, it will happen if you don't give a user input when the program runs. If there is only one input call, and you don't give an input for it, it will intepret the input as the empty string and only show the prompt (if there is one). However, if you have more than one input call, say two, and you don't give any inputs or you only give one, then you will get an EOFError, because the program is expecting two.
+ 3
EOF error means end of file ,which means that the program was calling for an input but failed to have any available input to READ in your case input ('\n smile')
+ 2
Thomas,
you are so boring! You think that you are an expert, but you're not. If you don't know to help and give instructions to people, so in that case, why are you here yet? Why are you so stupid and silly?
I am beginner, stupid and this is my second day learning here. I don't need to feel bad if I have doubt and came a stupid guy like you to show nothing, to answer nothing. I never will ask help for people like you, never.
Now, go to be more useful because your comments are like you, poor!
+ 2
Njeri,
Thanks a lot for your answer.
I have no doubts that people like you, make the difference in this community! I don't think I could receive a better explanation to my doubts.
I learned more than I expect with your answer. Again, Thank you so much!
+ 1
Thomas,
I want to know the difference and not where they take place.
Maybe you don't understand my question.
If you don't know explain, than don't say "sorry" because this will not solve my doubt.
+ 1
Jan?
I did a new test and I found the error.
Have a look in this example. The problem is where I start the command using a Capital Letter.
If you do:
input('\n smile')
Output: smile
But
If you do:
Input('\n smile')
Output:
Traceback (most recent call last):
File "./Playground/file0.py", line 5, in <module>
Input('\n smile')
NameError: name 'Input' is not defined
Thanks for your time and answer.
https://code.sololearn.com/291/#py
+ 1
Ana Carolina Thank you and I'm glad it helped.
+ 1
https://code.sololearn.com/ca9z1WWvqb9w/?ref=app
Plz check defference
+ 1
Thanks for all contributions,guys!
0
Grille hyper artistique
Recherche y â ù s le
Recherche
0
Souhail Belhassen,
Thanks!
0
Print is output, input is for getting user input
- 1
Ana Carolina , if you really ask for the difference between "input" and "print", I would say, you better start the python course from the beginn.
- 2
I've corrected my answer.
Wish you good luck for your programming future 👍