+ 1

How can you take input of an integer from the user in Python?

I used the command x = input() And it let me assign the value of x. However,when i try to perform operations with x,such as x+= 3,it shows an error.What can I do? Also,i want to perform arithmetic operations with x.I found it treats x as a string and not an integer.Please tell me how can i set x as an integer.

14th Mar 2019, 7:51 AM
Soham Roy
Soham Roy - avatar
6 Respuestas
+ 5
Please show your code. Did you use "input" as a variable name before?
14th Mar 2019, 8:05 AM
Anna
Anna - avatar
+ 5
Soham Roy It works for me, when I use this code: x = int(input()) x += 3 print(x)
14th Mar 2019, 8:11 AM
Rowsej
Rowsej - avatar
+ 3
x = int(input())
14th Mar 2019, 7:52 AM
Rowsej
Rowsej - avatar
+ 2
it doesnt work.When i write x = int(input()) it shows a type error and says string object is not callable
14th Mar 2019, 7:56 AM
Soham Roy
Soham Roy - avatar
+ 2
as i started with python just today,i was experimenting a bit of code and yes,i assigned input a value.I opened a new file and it is working now
14th Mar 2019, 8:08 AM
Soham Roy
Soham Roy - avatar
+ 2
Yes it will work
14th Mar 2019, 9:01 AM
Abhishek Yadav
Abhishek Yadav - avatar