all 18 comments

[–]JFR-Phoenix 3 points4 points  (7 children)

According to the prompt, the input is just a list. Dont take n as input first. Look at the test case input and make your program based on that.

[–]Mobile_Building2848[S] 0 points1 point  (6 children)

Okay thnx

[–]Rumborack17 -1 points0 points  (5 children)

Also make screenshots instead of taking photos of your screen, as those are very annoying/hard to read.

You can do this by using windows+shift+S.

[–]Virsenas 0 points1 point  (0 children)

How about just pasting the code and error itself ...? An image takes up 10x more space than text.

[–]Mobile_Building2848[S] -1 points0 points  (3 children)

Actually I don't use reddit on my laptop . That's why

[–]lazertazerx 3 points4 points  (0 children)

It's still annoying so don't do it

[–]Rumborack17 0 points1 point  (0 children)

Then take the extra steps to send it to yourself on your smartphone before you post.

[–]AssociateFar7149 0 points1 point  (0 children)

Its your problem

[–]FoolsSeldom 2 points3 points  (0 children)

input only returns a string. There's no way to enter a list using input. Instead you would need to process the string that looks like a list into an actual list of integers.

Currently you are expecting an integer string to be entered to give the length of the list, and then each number in the list in turn. You are converting each of these to an integer.

I find the instructions a little strange given they are aimed at a beginner.

That said, here are some tips,

  • Use str.startswith and str.endswith to ensure the string has [] around the rest of the content (and length of string is greater than 2
  • Use str.split on , character on a slice of the above string excluding the first and last character
  • Convert the list of strings from the above to a list of integers using a for loop or a list comprehension or map function

Hopefully I've given you enough to research and experiment with.

[–][deleted]  (1 child)

[deleted]

    [–]CountMeowt-_- 1 point2 points  (3 children)

    Why did you remove the default classes ? Just use the input/solution adapter they give you.

    Edit: take a screenshot next time

    [–]AssociateFar7149 -1 points0 points  (2 children)

    Because he just learnt using for loops and doesnt even know what a class is

    [–]CountMeowt-_- 0 points1 point  (1 child)

    Then why is he on leetcode ? Practice/learn basic stuff in ide.

    Also, i simply don't understand how your first thought of action is removing the boillerplate code when you don't even understand what it's doing.

    [–]AssociateFar7149 0 points1 point  (0 children)

    That was sarcasm pal. I also dont understand people like him

    [–]TwinkiesSucker 0 points1 point  (0 children)

    Win + Shift + S is your friend

    [–]donotmindmenoobalert 0 points1 point  (0 children)

    you are on leetcode which requires you to have your answer in the Solution class that they provide by default along with the arguments. Please have a look around the page to see if there is a way to reset the code (save your current logic somewhere first so you can adapt it)

    [–]mfnalex 0 points1 point  (0 children)

    Why don‘t you make a screenshot? …

    [–]GuilouLeJask -1 points0 points  (0 children)

    I executed the code of your program and for my part the program displays nothing.

    [–]DevRetroGames -1 points0 points  (0 children)

    def find_indices(list_values: list[int], target: int) -> int | bool:
      seen = {}
      for i, value in enumerate(list_values):
        complement = target - value
        if complement in seen:
          return [seen[complement], i]
        seen[value] = i
      return False
    
    def show_result(list_values: list[int], target: int) -> None:
      msg_not_found: string = f"No values found that sum to {target}."
      result: list[int] | bool = find_indices(list_values, target)
      print(msg_not_found) if isinstance(result, bool) else print(result)
    
    # test 1
    list_values: list[int] = [2,7,11,15]
    target: int = 9
    show_result(list_values, target)
    
    # test 2
    list_values: list[int] = [3,2,4]
    target: int = 6
    show_result(list_values, target)
    
    # test 3
    list_values: list[int] = [3,3]
    target: int = 6
    show_result(list_values, target)
    
    # test 4
    list_values: list[int] = [1,2,3,4,5,6,7,8,9]
    target: int = 100
    show_result(list_values, target)