Error int object is not subscriptable - Python

0 votes

I was trying a program in which you input someone's name and age and then it lets you know when they turn 21.  But I keep getting this error:  'int' object is not subscriptable.

My code.

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

Any help would be greatly appriciated.

Apr 29, 2022 in Python by Kichu
• 19,040 points
1,603 views

1 answer to this question.

0 votes

The issue is in the line:

int([x[age1]])


The solution you want is:

x = int(age1)


Convert the int to a string for the output.

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


This is the complete script:

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

I hope this helps.

answered Apr 30, 2022 by narikkadan
• 63,600 points

Related Questions In Python

0 votes
1 answer

i am normalizing the data set iris in python and get the error ::TypeError: 'numpy.float64' object is not callable

TRY THIS   #Nomalisation for i in names:     print(i)   ...READ MORE

answered Aug 20, 2019 in Python by Noel Deepak Palle
5,904 views
0 votes
1 answer

Python error "'Series' object is not callable "

Try this: df['ln_returns'] = np.log(df['Close_mid']/df['Close_mid']) df['Close_mid'](1)) doesn't seem to ...READ MORE

answered Jul 22, 2019 in Python by Greg
17,471 views
0 votes
0 answers

Python - TypeError: 'int' object is not iterable

Here's my code: import math print("Hey, lets solve Task ...READ MORE

Dec 21, 2022 in Python by erzan
• 630 points
834 views
0 votes
1 answer

Python Math - TypeError: 'NoneType' object is not subscriptable

“TypeError: 'NoneType' object is not subscriptable” is ...READ MORE

answered Jan 4, 2023 in Python by Elton
• 400 points
1,016 views
0 votes
0 answers

Error: 'int' object is not subscriptable - Python

I was experimenting with a straightforward piece ...READ MORE

Sep 21, 2022 in Python by Samuel
• 460 points
950 views
0 votes
1 answer

Error: 'int' object is not subscriptable - Python

int([x[age1]]) You are attempting to access the age1 index ...READ MORE

answered Feb 16, 2023 in Python by Rishu
• 300 points
962 views
0 votes
1 answer

Section postgresql not found in the database.ini file

Python doesn't know what $FILEDIR is. Try an absolute path ...READ MORE

answered Oct 3, 2018 in Python by Priyaj
• 58,020 points
3,683 views
0 votes
1 answer

Iterating over dictionaries using 'for' loops

key is just a variable name. for key ...READ MORE

answered Oct 8, 2018 in Python by SDeb
• 13,300 points
989 views
0 votes
1 answer

Python: Could not install packages due to an OSError: [Errno 2] No such file or directory

I also met with the same problem ...READ MORE

answered Apr 28, 2022 in Python by narikkadan
• 63,600 points
39,178 views
0 votes
1 answer

What is the difference between read() and readline() in python?

The read() will read the whole file at ...READ MORE

answered Apr 28, 2022 in Python by narikkadan
• 63,600 points
17,011 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP