117 AnswersNew Answer
Here's whats happening in the background. x = input("Enter input: ") is the same with x = input(15) - - - - - - - - - - - - - - - - - In this case the first one will be like this in the console. Enter number: The second one will be like this 15 - - - - - - - - - - - - - - - - - But you can still enter your input for both cases. For example I want to input my name " Nicko " Enter input: Nicko 15Nicko - - - - - - - - - - - - - As you can see here I can still input my desired input for both cases. The reason why it outputs 316 in your case is because here in SoloLearn, The input texts are displayed horizontally instead of vertically x = input(3) - - -> 3 is a text input y = input(16) - - -> 16 is a text input print(x + y) #And when you input nothing the SoloLearn console will be like this. 316 /*some errors*/ EOF to be specific - - - - - - - - - - - - - - - Try to input in sololearn like this: Hello World Then it will be 316 HelloWorld - - - - - - - - - - - -
Albanianz No, you don't need to...lets suppose you have this code: x = int(input(3)) y = int(input(16)) print(x + y) If the user enter, for example, 2 to x and 3 to y, the output will be 3165, instead of only the actual answer that is 5.
.Osama Deep. Can you not spam? You're only confusing the guy here.
If you write: x=int(input(3)) this number 3 does not effect the value of your variable x. It's only printed to the screen! So if you write... x=int(input(3)) y=int(input(9)) print(x+y) in a real ide it would print 3 to the screen then wait for your input, e.g. 5 -> this would look like 35 but x will be given the value 5 when you press <Return> then it jumps to the next line, prints 7 to the screen and waits for the next input, e.g. 3 -> <Return> -> next line. In this next line the sum of x=5 and y=3 is printed. In sololearn's playground you have to give all your input in one go. So it waits for two inputs, you submit the values and the code is executed, which means 3 is printed (no new line), 7 is printed (no new line)->now it looks like 37 (again no new line) -> now the sum of your submitted values is printed, e.g. 8... Now it looks like 378, but the result of adding 5 and 3 is 8! But what's your idea behind int(input(3)) ? What do you really want the code to do?
Albanianz the parameters passed to input() are always printed in the screen, usually to let the user what should be entered as input. E.g. name = input("Your name:") print(name) Output: Your name >>>_ As SoloLearn doesn't have an interactive console you can't use it properly
Albanianz that 5 is the result of the sum in my example. Just copy the example and try it, first without the parameters in input, then with the parameters and you will see.
.Osama Deep. This could be explained in one comment like Царь СОБАКА - Догго I did. Dont confuse people like that lol.
Albanianz Here in SoloLearn if you input nothing in the input box, the variable that needs input wont have input so it will cause an error. What Crash did is to prevent that error by using default values with exception statements. If you input nothing, the code will cause an error so the except statement runs and the variable will have the value and there will be no error cause the variable now has the value. Although I dont think this is necessarry for you to know it right now as you will learn it eventually. Thanks and Keep Learning!!
x = int(input()) y = int(input()) print(x + y) If both variables are going to be inputs, why do you "give" them values?
Albanianz I still wonder what you wanted to do with the numbers in the brackets. Did you want to use default values if the input is invalid? Then this could be something for you: ... https://code.sololearn.com/cF7E5m1CMH5V/?ref=app
Kode Krasher Thank you for sharing the info and the link. I'll definitely check this out!
Albanianz there are many ways to accomplish the same task. Once you get more familiar with the language and the way Sololearn takes input, you will be able to write the same code many different ways. I encourage you to explore, and see if you can do the same thing with different code structures. It will help you understand the most efficient and most readable ways to code. 😎👍
Albanianz when you add those values inside input(), they are also printed along with the answer... and I don't see why would you want to do so.
the argument accepted by the input function is what the user will see as prompt on the terminal instead of a blinking cursor only. Also the input function ALWAYS returns the input as a string.
Crash I didn't want to do something specifik, I didn't understand what input is for and I saw a youtube video writing it like that so I was wondering why it says error
You must convert the string to a numerical value using int or float function. Hope it helps!!!
Albanianz int stands for integer as opposed to str which stands for string. By default all input is a string. By "casting" (changing) the input to an integer it allows the variable inputted to have math applied. If you do not cast the input from a string to an integer the variables will be concatenated as strings.
Albanianz it looks like you have just started the python tutorial. You should continue on and learn about the different data types, and working with input to understand the concept. If you want to watch youtube videos, I highly recommend this playlist to supplement the Sololearn tutorial: https://youtube.com/playlist?list=PLi01XoE8jYohWFPpC17Z-wWhPOSuh8Er- It will give you a good overview of the language. The best way to learn is to do a learning module and practice! Do it in steps so you can understand and recall what you learn. Jumping ahead to topics you haven't studied will only confuse you. Happy Coding! 😎👍
Albanianz that is good! Take your time and practice everything you learn. I spent 3-4 hours a day for 4 months and feel I learned the basics pretty well in that time. My goal was to pass a certification exam, and I accomplished that in 6 months. It can be done much quicker, but to understand the language you must practice. If you want to see what I studied and the path I took to certification, look at this thread: https://www.sololearn.com/discuss/2153816/?ref=app Happy Coding! 😎👍
Albanianz I knew it would be difficult for you, but it should help others understand also, and it can provide you an example when you get to that section of the tutorial. 😉 Remember that code playground has thousands of examples, so learn to use the search bar to find codes that might help you. And change codes you look at to see how the changes effect the output. You will learn much faster that way. Glad I could help. 😎👍