Error int object is not subscriptable - Python

0 votes

I was experimenting with a straightforward piece of code that would simply take a person's name and age and notify them when they turned 21 without taking into account any bad factors.

This "int" object is not subscriptable issue keeps occurring.

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

Feb 15, 2023 in Python by Arya
• 990 points
724 views

1 answer to this question.

0 votes

int([x[age1]])

You are attempting to access the age1 index of the x number here, which is illogical. Additionally, you are attempting to cast the result back to an integer after putting it in a list, which is not required.

Instead, use the int() function to immediately cast the age1 input text to an integer, as in the following example:

name1 = input("What's your name? ")
age1 = int(input("how old are you? "))
twentyone = 21 - age1
print("Hi, " + name1 + ", you will be 21 in: " + str(twentyone) + " years.")

After this, error will be terminated.

Master the art of Data Science with Python and unlock the power of insights.

answered Feb 16, 2023 by Rishu
• 300 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,566 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,178 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
629 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
811 views
0 votes
1 answer

Error: 'int' object is not subscriptable - Python

The issue is in the line: int([x[age1]]) The solution ...READ MORE

answered Apr 30, 2022 in Python by narikkadan
• 63,700 points
1,386 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
779 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,090 points
3,292 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
852 views
0 votes
1 answer

Relative imports in Python 3

Because the first statement, from.mymodule import myfunction, ...READ MORE

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

Replacements for switch statement in Python?

To get the same function as a ...READ MORE

answered Feb 16, 2023 in Python by Rishu
• 300 points
938 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