I was trying a simple piece of code, get someone’s name and age and let him/her know when they turn 21… not considering negatives and all that, just random.
I keep getting this 'int' object is not subscriptable error.
name1 = raw_input("What's your name? ")
age1 = raw_input ("how old are you? ")
x = 0
int([x[age1]])
twentyone = 21 - x
print "Hi, " + name1+ " you will be 21 in: " + twentyone + " years."
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[34], line 4
2 age1 = input ("how old are you? ")
3 x = 0
----> 4 int([x[age1]])
5 twentyone = 21 - x
6 print "Hi, " + name1+ " you will be 21 in: " + twentyone + " years."
TypeError: 'int' object is not subscriptable
The problem is in the line,
What you want is
You also need to convert the int to a string for the output…
The complete script looks like,