+ 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.
6 Réponses
+ 5
Please show your code. Did you use "input" as a variable name before?
+ 5
Soham Roy It works for me, when I use this code:
x = int(input())
x += 3
print(x)
+ 3
x = int(input())
+ 2
it doesnt work.When i write x = int(input()) it shows a type error and says string object is not callable
+ 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
+ 2
Yes it will work