How To Fix Typeerror: 'float' Object Is Not Subscriptable And An .append That Isn't Working
Solution 1:
To fix your .append
issue (also your second return
statement is never going to execute, see below on how to return both lists):
Your loop isn't continuing is because you're returning inside the loop, thus terminating the function. Move your return
statement outside of the loop (single unindent).
while not done:
# do stuffreturn salary, names
To fix your TypeError
I think the problem is here:
for i inrange(len(names)):
salary = salary[i] * 1000# Up to this point salary is a list, here it turns into the ith value of the list multiplied by 1000print(salary)
Instead, replace that entire for loop with:
salary = [s*1000 for s in salary]
for s in salary:
print(s) # This should now print the multiplied salaries.
Some other issues - you have two return
statements followed by one another - the function will finish executing after the first return, and never execute the return below that one; if you want to return both salary
and names
use return names, salary
(and maybe rename salary
to salaries
so that people can easily tell that it's a bunch of salaries, not just one).
Post a Comment for "How To Fix Typeerror: 'float' Object Is Not Subscriptable And An .append That Isn't Working"