How to input | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to input

Someone Explain to me the input() function, pls 😓

15th Apr 2022, 12:04 PM
Rayan Chan
Rayan Chan - avatar
37 Answers
+ 5
Developers often have a need to interact with users, either to get data or to provide some sort of result. Most programs today use a dialog box as a way of asking the user to provide some type of input. While Python provides us with two inbuilt functions to read the input from the keyboard. input() function first takes the input from the user and convert it into string. Type of the returned object always will be <type ‘str’>. It does not evaluate the expression it just return the complete statement as String. For example –  val = input("Enter your value: ") print(val) When input() function executes program flow will be stopped until the user has given an input. The text or message display on the output screen to ask a user to enter input value is optional i.e. the prompt, will be printed on the screen is optional. Whatever you enter as input, input function convert it into a string. if you enter an integer value still input() function convert it into a string. You can use typecasting for more types.
17th Apr 2022, 2:53 AM
follow ->
follow -> - avatar
+ 9
The input function in python is basically used to collect value from the user something like Name = Input('What is your name: ') print(Name) If you run this on the terminal the user can actually input his or her name and the users input would be assigned to the variable Name. When we print out name it gives us whatever input the user submitted
15th Apr 2022, 3:01 PM
Awwal Sadu
Awwal Sadu - avatar
+ 6
If you want to create a facebook account, you need to fill a form after you click the sighup button. The form takes the input and saves your given details at some place from where it can be taken to display on your profile (when you go to your profile page) , to someone (when you send them friend request) or to the owner of the facebook company. For all these we need to take your details on a form and this data is the input you provide on which we do our operations to use it in our product and provide you the results. For that (in python) we can do by creating variables A , B etc. (what is variable?) A= input(“Enter your first name: ”) B= input(“Enter your last name: “) And then whereever we want to show your first name or last name or even both, we can simply pass a print command. Like in your profile page Print(a) Print (b) Print(a+b) Etc. And if you do not upload the image on your profile pic. We can also print first alphabet of your first name or last name like you get in Gmail. How? Using index.
16th Apr 2022, 5:52 PM
+ 4
It's something what device, program or process gets from outside eg data or commands
15th Apr 2022, 12:12 PM
Simba - avatar
+ 4
Actually in Python you *can* multiply a string... Try print("yo" * 3) and you get "yoyoyo". Get it now?
15th Apr 2022, 1:57 PM
+ 3
Rayan Chan you just need only one variable x = input() print(x) coolCool is a strint so no need to use int edit: or you can write just print("coolCool")
15th Apr 2022, 12:34 PM
NonStop CODING - avatar
+ 3
Input is a way to take “input” or data from a user. Think of it this way, whenever you sign up for an account on any website, what is the first thing you do? You input your email, desired username, password, etc. The developers of these websites set up the code for the account creation forms that allow for user (input). Same for a calculator, it takes your input and outputs the answer after running calculations(codes). input( ) allows you flexibility on what your users can do with your code. Example: user_name= input () print(“Hello “ + user_name) With the above code, the program will greet the user with the username they made. #side note * all input is output as a [string] * strings are phrases. * this means a number [integer] will also be output as a [string]phrase. *if you try to multiply or add [strings] together this happens Example: print(“hot”+”dog”) hotdog print(“1”+”3”) 13 (it’s onethree not thirteen) Or print(“cat” * 3) catcatcat print(“3” * 3) 333 (strings repeat not multiply)
16th Apr 2022, 11:22 PM
Eric - avatar
+ 3
Andrew Musanyera Eric Osman Matar Rajeev Sharma Appreciation for the help 🙏 It helped me understand more 🙏
17th Apr 2022, 3:20 AM
Rayan Chan
Rayan Chan - avatar
+ 2
by default input() makes any data entered by user a string so to input integer value, use int(input()) for float, use float(input()) store it in a variable varibleName = input() # stores string variablName = int(input()) # store int variableName = float(input()) # store float
15th Apr 2022, 12:14 PM
NonStop CODING - avatar
+ 2
Input is a funcation، each function has an input and output, input() method receive data in parantese and return the output .. I hope it helps you
15th Apr 2022, 5:36 PM
‎Saeed.Mohammadi.Aghdam - avatar
+ 2
Working of Python Input () When we use the input () function in our program, the flow of execution is halted till the user inputs the data and clicks the Enter button. After that, the user’s value input is stored in some variable in the form of a string. (Or number) Example: Color = input(“Enter color: ”) print(Color) To make the user input a number we use: int(input()) Example: num = int(input(“Enter a number”)) print(num) Hoped this helped
15th Apr 2022, 6:04 PM
Joseph Boateng
Joseph Boateng - avatar
+ 2
RAP1DW0LF Thank you 🙃.. it helped √
15th Apr 2022, 8:00 PM
Rayan Chan
Rayan Chan - avatar
+ 2
To put it simply it's a function that allows you or the user to put information into your program and you have to assign it to a variable so that the input value is stored into the variable for use. It takes all input in a string input so if you want to use it to collect numerical data use the int function e.g var = int(input("so and so"))
16th Apr 2022, 9:30 PM
Andrew Musanyera
Andrew Musanyera - avatar
+ 1
It collects value from the user
15th Apr 2022, 1:37 PM
Olufikayomi Jetawo
+ 1
Erik thanks😬
15th Apr 2022, 3:40 PM
Rayan Chan
Rayan Chan - avatar
+ 1
You could also use the help function for situations like this
16th Apr 2022, 12:20 AM
Andrew Johnson
Andrew Johnson - avatar
+ 1
The input function just gets data input from the user. Just declare a variable and assign it to the input function. The string in the input function is optional.
16th Apr 2022, 10:57 AM
Chi Zu
Chi Zu - avatar
+ 1
The input function allows you to enter and collect information within a print statement. username = input(“What is your username?: “) print(“Hello”, username) (Say I put “Brandon” into the username input.) The output comes out to be: Hello Brandon However, you can use it into other ways such as making a text blackjack game. You can ask if one wants to hit or stand and you can have it do the following: hitorstand = input(“Would you like to hit or stand? Please enter ‘h’ or ‘s’.”) if hitorstand == “h”: # assume there is a draw card funtion here. draw_card() if hitorstand == “s”: # assume the dealer reveals his card function here dealer_reveals() You can store integers within the input by saying: numbertoenter = int(input(“What number would you like to assign?: “)) print(“Your number is: “, numbertoenter) If you want to store a float say: floatstore = float(input(“store float”)) I hope this helped in anyway. I was confused at it at first when I was learning Python.
16th Apr 2022, 6:53 PM
Brandon Wood
+ 1
There are two ways to take input 1) pre defined inputs which we assign to the variable before executing. 2) User input which we take from the user in this form First= input(“Enter first name : “) Print(First)
16th Apr 2022, 7:30 PM
Anita Shah
Anita Shah - avatar