Oct-11-2019, 11:29 PM
(This post was last modified: Oct-11-2019, 11:38 PM by GalaxyCoyote.)
(Oct-11-2019, 10:35 PM)ichabod801 Wrote: If I setRow1 = ['-', '-']
, I have no problems with the code. Of course, that's because it's not really doing anything, is it? It gets the input, starts the inputloop, and calls itself, which gets the input, starts the input loop, and calls itself, and so on until you get a RecursionError.
Perhaps that is being masked by your overly broad except statement. Except statements should be as narrow as possible, in this case only caching ValueError.
Regardless of the problems of using a global variable like Row1 (pass it as a parameter to the function instead), this should be a loop:
def qinput(Row1): inputloop = True while inputloop: try: Pinput = int(input("Where would you like to go?: ")) except ValueError: print('Integers only please.') continue if Pinput == 1 and Row1[0] == "-": #checks if the position is free Row1[0] = " " inputloop = False elif Pinput == 2 and Row1[1] == "-": Row1[1] = " " inputloop = False else: print("invalid position - already taken!") return PinputAnd if the existence of Row1 implies the existence of Row2 and maybe Row3, I would suggest putting them in a list.
This may sound like I am an idiot but I just get this error...
TypeError: qinput() missing 1 required positional argument: 'Row1'
(Oct-11-2019, 11:29 PM)GalaxyCoyote Wrote:Extremely sorry! I wasn't reading my code correctly, there was no issue I had just forgot to add in Row2 and Row3.(Oct-11-2019, 10:35 PM)ichabod801 Wrote: If I setRow1 = ['-', '-']
, I have no problems with the code. Of course, that's because it's not really doing anything, is it? It gets the input, starts the inputloop, and calls itself, which gets the input, starts the input loop, and calls itself, and so on until you get a RecursionError.
Perhaps that is being masked by your overly broad except statement. Except statements should be as narrow as possible, in this case only caching ValueError.
Regardless of the problems of using a global variable like Row1 (pass it as a parameter to the function instead), this should be a loop:
def qinput(Row1): inputloop = True while inputloop: try: Pinput = int(input("Where would you like to go?: ")) except ValueError: print('Integers only please.') continue if Pinput == 1 and Row1[0] == "-": #checks if the position is free Row1[0] = " " inputloop = False elif Pinput == 2 and Row1[1] == "-": Row1[1] = " " inputloop = False else: print("invalid position - already taken!") return PinputAnd if the existence of Row1 implies the existence of Row2 and maybe Row3, I would suggest putting them in a list.
This may sound like I am an idiot but I just get this error...
TypeError: qinput() missing 1 required positional argument: 'Row1'