What is a INPUT ? Input is any data, information , or value that is sent by the user to the computer for further processing. Looking by the picture beside, let’s try our first input at IDLE Python Try this code !
Knowing the data type of input If we look at the previous program, the user can enter any value or data. It can be a number , date of birth, even emoji Then what is the return value data type of the input() function? The return data type is “STRING” Let's prove it.
More with input Let’s try this code below ! Observe and What does the program do ? What the result ?
Further with input ! Yeahh !!! See,,, !!! The result from the previous program show you the data type of INPUT always “STR” or you can call it “STRING”. Still don't believe ? Oke , if before we always wrote the input using text was is a STRING. Now let’s try with another input using number rewrite this program ! See, the result of the previous code show you the data type was “STR” or “STRING”
Same with previous result, even you write the input using number the data type still STR or STRING. So what the effect if we only get the data type as STR( Sring ) and can’t get the data type as INT (Integer) or FLOAT type ? Oke , let’s try this code again ! What the result ?
Error !!! Error right ? And the result was shown is a … Oke , keep calm ! And Why error? because we are trying to multiply two values of type string data, and it will cause an error like the one above in the python programming language. Then what is the solution if we want to multiply two numbers resulting from user input? The trick is to convert the data type!
Fix the error ! 1 st way : 2 nd way : The 1 st way is a put the Sintax code for convertion after write The input code. You need to write the name of variable first and separate with (=) simbol and then write the new data type (also can use float) and for the last write again the name of variable was you want to convert the 2 nd way is that you can convert the data type directly when you want to use calculation operations