World's Best AI Learning Platform with profoundly Demanding Certification Programs
Designed by IITians, only for AI Learners.
Designed by IITians, only for AI Learners.
New to InsideAIML? Create an account
Employer? Create an account
name = input("What's your name? ") age = input ("how old are you? ") n = 0 int([n[age]]) twentyone = 21 - n print ("Hi, " + name + " you will be 21 in: " + twentyone + " years.") Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'int' object is not subscriptable
How to solve this error?
The problem is in the line,
int([n[age]])
What you want is
n = int(age)
You also need to convert the int to a string for the output...
print ("Hi, " + name + " you will be 21 in: " + str(twentyone) + " years.")
The complete script looks like,
name = input("What's your name? ") age = input ("how old are you? ") n = 0 n = int(age) twentyone = 21 - n print ("Hi, " + name + " you will be 21 in: " + str(twentyone) + " years.")