I'm building an application that allows for user tracking of basketball scores. For example, if a team shoots a free throw, they press a 'Free Throw' button under the scoring team's header and one point is added to the displayed score. I'm using Python 3.x and want to know if I can write function arguments that will be specified as either the home or the away score variable and then have the specified score be updated. Currently, I have separate functions for each type of score for each team, meaning I essentially have duplicate code minus the differences in 'home' and 'away'. Both home and away score are saved as globals due to requirements for interfacing with other software. Am I stuck with 6 total functions, or can I write 3 and just specify which global I want updated when I call the function? Sample non working code attached
global away_score
away_score = 0
global home_score
home_score = 0
def plus_one(inc_score, inc_frame):
inc_score += 1
inc_frame.config(text = inc_score) # this is for interfacing with tkinter
inc_scoreinsideplus_oneis a local variable created inside the function, and thus only in scope inside there. It does not refer to the parameterinc_score, whose value you would pass as an argument when callingplus_one.return. Usereturn inc_scoreinplus_oneand thenhome_score = plus_one(home_score, ...)and the sameaway_score = plus_one(away_score, ...)global. We useglobalinside function to inform funtion that it has to use external/global variable instead of creating local one.