Error: int object is not subscriptable – Python
Error: int object is not subscriptable – Python
When you type x = 0
that is creating a new int
variable (name) and assigning a zero to it.
When you type x[age1]
that is trying to access the age1
th entry, as if x
were an array.
The problem is in the line,
int([x[age1]])
What you want is
x = int(age1)
You also need to convert the int to a string for the output…
print Hi, + name1+ you will be 21 in: + str(twentyone) + years.
The complete script looks like,
name1 = raw_input(Whats your name? )
age1 = raw_input (how old are you? )
x = 0
x = int(age1)
twentyone = 21 - x
print Hi, + name1+ you will be 21 in: + str(twentyone) + years.
Error: int object is not subscriptable – Python
When you write x = 0
, x
is an int…so you cant do x[age1]
because x
is int