Explain with an example how you can use input() function to assign integer value to a
variable.
Answers
Answer:
To take integer input from the user:-
x = input("Enter an integer >>>")
print "You have entered",x
Output
Enter an integer >>>12
You have entered 12
int changes a string to an integer. For example, int('12') will give us an integer 12.
In the above example, we are taking the input from the user as a string with the input() and then we are using the int() to change it to an integer. So, if a user will enter 10, then the input() will become '10' (a string) and the above statement int(input()) will become int('10') and we will get 10 as an integer.
We can also break the above example in one more step to understand better.
x = input("Enter an integer >>>")y = int(x)print("You have entered",y)
Output
x = input("Enter an integer >>>")y = int(x)print("You have entered",y)OutputHere, we passed 12. Thus, x became '12' and then int(x) turned it into an integer.
The 'raw_input()' of Python 2 is same as 'input()' of Python 3 and the 'input()' in Python 2 is used to directly take integer inputs from a user.
hopefully this will help you!!!
please mark my answer brainliest if you like
plz follow me and support me
thank you !!!!!!!