#πŸ”’ My IDE thinks each item in a list is a list

38 messages Β· Page 1 of 1 (latest)

clever quiver
#

`def sum(*input):
nums = []
result = 0

for i in input:
    if input.count(i) == 1:
        nums.append(i)

for j in nums:
    result += j

print(result)

sum(8,8,8,1,2,3)`

This is the code I'm working with. The PC interpreter understands it just fine, the output is 6 as expected. The python codepad on my phone says result += j is an error, "unsupported operan for +=: 'int' and 'list'. I've checked to make sure the code is exactly the same and there are no errors in the indentation, still won't work.

fickle fossilBOT
#

@clever quiver

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

clever quiver
#

Same python versions on both as well

strong moss
clever quiver
#

Weirdly enough, it executes just fine outside of the challenge tab

strong moss
#

so input is a list of lists

clever quiver
#

I don't know what that means πŸ˜…

strong moss
#

try running sum([])

clever quiver
strong moss
#

there you go, your program isn't designed to handle lists as input

clever quiver
#

Weird..I tried just not calling the function and got this

#

...I think that means I got the exercise right?

pulsar dew
#

the example snippet only showed integers as input, not lists

strong moss
clever quiver
pulsar dew
#

what is this code user_result = sum([])?

strong moss
#

it looks like some kind of autograder

clever quiver
#

the goal is to add all the numbers that aren't being repeated

#

I just realised it actually never worked in the exercise tab. It worked outside of it though. Is it safe to assume the app is just buggy and for all intents and purposes, I solved the exercise correctly?

hearty gust
clever quiver
#

but why ?

hearty gust
#

check to make sure you read how it's going to call your function correctly

clever quiver
#

im not sure how to do that

hearty gust
#

I mean, read the problem that you're trying to solve again

#

it should include an example or description on how the grader will call your function

clever quiver
#

Oh I see what you mean, this was the prompt

hearty gust
#

yeah

#

so the grader is calling sum([1, 2, 3])

#

and so you're *args is turning that into a list of lists, hence your issue

clever quiver
#

OH I should just remove args

#

I was going on a whole tangent to split the input into a list of integers and realising that made no sense either

#

typcasting result as an integer only worked outside of the exercise tab again

#

I did it, just changed print() to return lol

fickle fossilBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.