Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Recursive Function
#1
Hey Guys,
I got homework from university but we never learned anything that has to do with it, so I'm really confused with this.
I got a list with games from a tournament. The first 8 games are the first round. In this round the Teams are defined by TXX, XX as their number. Every game got an ID and to define who won there is 0 or 1 (0 = left team won, 1 right team won). After the first round, all teams are redefined every round by WXX or LXX, W being for winner and L for loser and the XX is the gameid from the game which defined their W or L so W27 means it is the winner from game 27.
Now i got the code which is written in the file (see code) and my task is to write recursive function without using for or while and this function needs to find the initial name of the winner from the last game. So it needs to check all their games and names back to the first round where they had the TXX name.
I'd really appreciate any help.
Thanks a lot! - Thomas
Reply
#2
Read this: https://www.python-course.eu/recursive_functions.php
Reply
#3
Ok, so this looks pretty straightforward.

Have you tried using the interactive shell, entering the key code of the function (copy and paste) and checking what happens?

Inside the get_team() function, game holds the list for the gameid of interest. This is a list of three elements, namely two team strings (each of which are one of: "Wxx" or "Lxx" or "Txx") followed by a number, 0 or 1, telling which team won (either the team in the first list position, position 0, game[0], or the team in the second list position, position 1, game[1]).

Subsequently, team holds the name of the team of interest ("Wxx" or "Lxx" or "Txx") which means the last two characters, given by team[-2:] (i.e. counting backwards by 2 from the end of the string, give me the slice of the string from there until the end) which when converted to an integer, gives you the game id you need to check for that team of interest (either as a winner or looser, indicated by the first character, team[0] in team if it is not a T. If it is a T of course, you have found the team you are looking for.

I think you only need to add two lines of code, and the first line is an if statement.
I am trying to help you, really, even if it doesn't always seem that way
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,806 May-13-2020, 04:01 PM
Last Post: jefsummers
  Recursive Function - Compare 2 lists, return the elements that don't exist in both KellyBaptist 1 5,219 Dec-23-2018, 10:10 AM
Last Post: Gribouillis
  Storing Minimum List of values from a recursive function sigsegv22 1 2,528 Sep-10-2018, 01:25 PM
Last Post: ichabod801
  Recursive function with a parameter MOH 0 2,051 Apr-30-2018, 09:39 PM
Last Post: MOH
  Recursive function need help Neural_oD 4 5,997 Aug-01-2017, 09:23 AM
Last Post: Neural_oD
  Recursive function janek30 1 2,874 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