Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
5 views
in Python by (47.6k points)
edited by

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."

closed

1 Answer

0 votes
by (106k points)
edited by
 
Best answer

You are getting the error because of the following line:-

int([x[age1]])

So, to get rid of the error you need to convert the int to a string for the output see the code below:-

print "Hi, " + name1+ " you will be 21 in: " + str(twentyone) + " years."

The complete code is as follows:-

name1 = raw_input("What's 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."

To know more about this you can have a look at the following video tutorial:-

Related questions

0 votes
1 answer
0 votes
2 answers
0 votes
1 answer
0 votes
1 answer
asked Jul 4, 2019 in SQL by Tech4ever (20.3k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...