Using input() method to read values

Lesson Details:
September 17, 2020

Video Transcription: In this interesting lecture we will learn how to read the values in two variables using input method this video is brought to you by Appy Pie’s Academy, have already created a an empty program with the name int y dot py so I'm going to write the code first let me give some pertinent comment so I'm writing a sh in learning to read values in two variables through the keyboard so as you know reading the values means inputting the values so we'll be inputting the values through the keyboard and the values they should go into a variable so the first thing I am going to do is name is equal to input and no know what will happen in case of name is equal to input his name is a variable and input is a method at the time of execution of input the cursor will start blinking that means it is asking for some value to be read from the keyboard user will give a value and subsequently that will go into the variable name but to make the things clear to the to the user we should give a print statement like enter the name of the candidate before this cursor blinking so that user comes to know what he is supposed to supply so this is called prompt so whatever will be inputted that will go into the variable name written onto the left side of the assignment operator is equal to so subsequently in the next statement I have simply printed the name is colon within quotes will be printed as it is and plus concatenation symbol will concatenate that is join the variable name so let me execute this program okay so I think there is some problem with the indentation okay so as you know by working in Python you shouldn't give space before any programming statement unless it is required so let me remove the space right okay so we executed the program it is asking for the name of the candidate this enter the name of the candidate ASIS is coming from the simple print statement and then name is Anand Mahajan because value was supplied on an margin and this value was given through the input method so input method is used to read the values to input the values through the keyboard now we will move further and here I am going to tell you a very important point that when you people use input method whatever value you supply that is taken in the form of a string right so in order to make these values work as int that is integer or float we are supposed to convert their type it's very easy let me explain it with the help of these coding statements so I have written enter the first value where one is equal to input so whatever value we will give through the input method that will go into the variable var1 subsequently we have given the statement print enter the second value and this this is the prompt enter the second valuable message will appear after that because of input the cursor will start blinking and whatever value user supplies that will go into bad - but both the values into mehrman and by - they will be treated as strings but what I want to do is I want to add these two numbers but right now they are not being treated as numbers but they are being treated as strings so first let me give the comment because this is very important when we give a prompt message to the user - to make it to make understand what kind of data he is supposed to give so these messages enter the first value enter the second value they help the user a lot regarding what kind of data he is supposed to give now I am writing some : and after that bad three I am going to execute this program but you will see that there will be very strange output because where one bad two were treated as strings so I have executed the program I have given the value first value under second 1000 and as you can see actually we wanted to add these two numbers but it is simply concatenating them as two strings one double zero was the first value one triple zero was the second values they have been simply concatenated like strings so this is not what we want so what I will do is I will use int typecasting this is called typecasting int where when int bad to now what will happen is we are one bad - they will not be considered strings they will be considered integers so I have again we executed the program Valdez 100 and suppose second value is again 1000 or something yeah now we got the desired result both the values they have not been concatenated but they have been actually added together because of this plus symbol so this point is very important that when we use input it takes only string so it takes input takes in the form of string only so but there is this is not a major problem because you have seen in this example we wanted to wear one and bad to to be treated as integers so we just prefixed them with the name with the with with the keyword int so they were converted into integers and we got the desired output. 

Course content