Python Forum
Recursive function with a parameter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Recursive function with a parameter
#1
Hey,

As a homework, I have to define a function that returns a frozenset of the positions who are going to explode (the function is_to_explode() is already defined and works). So what this function does, is, given a board, (defined as a list), I’d have to check each elements to know if in this position the element will explode, and that by using a recursive way, well I just don’t see a startpoint. I wrote a function, but actually it doesn't work and I don't see why.

Well if anyone could help, it’d be really great

Thanks in advance.
--------------------------------

def get_all_positions_to_explode(board,start_pos=(1,1)):
    """

        RECURSIVE !!!

        Return a frozen set of all positions on the given board that
        have a disk that satisfies the conditions to explode, starting
        from the given position and proceeding to the top of the board
        using the next function.
        - The function returns the empty set if the given start position
          is None.
        ASSUMPTIONS
        - The given board is a proper board.
        - The given start position is either None or it is a proper position
          for the given board.
        NOTE
        - The second parameter should not be included in the code that
          is given to the students. They must learn to extend functions
          with extra parameters with a default value. The documentation
          of the function must be changed in view of that.
    """

    lst = set()

    if start_pos[1]> len(board):
        return frozenset(lst)

    for col in range(1,len(board[1])):

        pos = (col,start_pos[0])
        if is_to_explode(board,pos)==True:
            set.add(lst,pos)

    return get_all_positions_to_explode(board,(1,start_pos[1]+1))
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  "Plotting and Computation of Logistic Function by Using Taylor Series with Recursive canatilaa 1 1,875 May-13-2020, 04:01 PM
Last Post: jefsummers
  A function taking in parameter int and str GrosseGaro 1 2,412 Sep-25-2019, 06:20 PM
Last Post: ichabod801
  Recursive Function - Compare 2 lists, return the elements that don't exist in both KellyBaptist 1 5,314 Dec-23-2018, 10:10 AM
Last Post: Gribouillis
  Storing Minimum List of values from a recursive function sigsegv22 1 2,593 Sep-10-2018, 01:25 PM
Last Post: ichabod801
  parameter in function being involuntarily converted to str?? juliabrushett 8 4,709 Jul-03-2018, 04:23 PM
Last Post: gruntfutuk
  function with radius as a parameter that returns area of a circle taydeal20 4 7,292 Feb-07-2018, 03:33 PM
Last Post: buran
  Recursive Function Fanki 2 3,068 Dec-06-2017, 11:40 AM
Last Post: gruntfutuk
  Recursive function need help Neural_oD 4 6,074 Aug-01-2017, 09:23 AM
Last Post: Neural_oD
  Recursive function janek30 1 2,939 May-16-2017, 04:58 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020