how to take input in Python 3| how to take integer input in python 3

By | October 3, 2019

how to take input in Python 3| how to take integer input in python 3

Coding Screen how to take input in python and typecasting in python:-

how to take input in Python 3| how to take integer input in python 3

Duplicate Code

how to take input in Python 3| how to take integer input in python 3

and typecasting in python:-

1-print(“Enter your value”)
2-value1=input()
3-print(“your entered value is”,int(value1)+90)

4-print(“enter first value”)
5-val1=input()
6-print (“enter second value”)
7-val2=input()
8-print(“sum of entered values are”,int(val1)+int(val2))

Solution Screen how to take input in Python 3| how to take integer input in python and typecasting in python:-

how to take input in Python 3| how to take integer input in python 3

Today I will tell you “How to take input in Python 3” and “How to typecast a value in python 3”

You can see in coding screen

1-print (“Enter your value”)
 

In this line we are just telling our user to enter some value it is just a printing statement which user can see but if he entered a value than what happen “nothing”

Because here program is not going to take any value or store any value so how to take input in python

2-value1=input ()

This is our second line input () is a predefined function in python here it will take input from user and just store in variable(it is just used for storing value) named Value1

But remember one thing what?

It will always take value in string form

what does it mean ?

Let us understand by some example

If user enter a name Bharat Chandra joshi

This is a string value and it will store in variable named value1 and we know this is a string and also user entered it as a string

But what happen when he entered 10

Here also 10 is also stored in variable value1 as a string surprising?

Ok let us understand by this

3-print (“your entered value is”, int(value1)+90)

In this line remove int

        Print (“your entered value is”, (value1) +90)

Here what happen value1 in which string value that is “10” is trying to sum-up with 90

And we want 10 which is stored in variable value1 sum up with 90 and we want it to print 100

But try this out it will show error

Because how can a string value is added with a integer value

so what is the solution of this problem ?

 here we have a solution in python that is typecasting

Now what is typecasting, Typecasting is simply converting one type of value to another type

Here we have to convert value 10 which is taken as a string by python predefined function input () to a integer value like this

3-print (“your entered value is”, int(value1)+90)

Here we have converted 10 which is stored in variable value1 as a string to integer value int(value1) and now here this string value is converted to integer value.

Now lets take another example

1-print(“Enter your value”)
2-value1=input()
3-print(“your entered value is”, int(value1)+90)

how to take input in Python 3| how to take integer input in python 3

Now take another example of how to take integer input in python 3

4-print(“enter first value”)
5-val1=input()
6-print (“enter second value”)
7-val2=input()
8-print(“sum of entered values are”,int(val1)+int(val2))

how to take input in Python 3| how to take integer input in python 3
how to take input in Python 3| how to take integer input in python 3

Here first

User entered 67 it is stored in variable val1 as a string and again user has entered second value that is 67 it is also stored in variable val2 and then we have converted our string value to integer value by typecasting in line 8

8-print (“sum of entered values are”, int(val1)+int(val2))

Than the result value is 134.

Latest Government jobs in India USA UAE UK Nigeria and Canada @graduatejobs360.com

graduatejobs360

Leave a Reply

Your email address will not be published. Required fields are marked *