Python says: "IndexError: string index out of range." -
i making practice code game similar board game, mastermind-- , keeps coming out error, , can't figure out why it's doin it. here's code:
def guess_almost (guess, answer): = ''.join([str(v) v in answer]) g = str(guess) n = 0 = 0 while n < 5: if g[n] == a[0]: = + 1 if g[n] == a[2]: = + 1 if g[n] == a[3]: = + 1 if g[n] == a[3]: = + 1 n = n + 1 return(am)
okay, guess specified 4 integers, , reply list containing 4 numbers. both have same 'len' after code, don't have clue.
the point of code turn reply string of 4 numbers, , see if of numbers match thoise of guess, , homecoming how many total matches there are.
see if helps
def guess_almost (guess, answer): = ''.join([str(v) v in answer]) g = str(guess) n = 0 = 0 if len(g) >= 5 , len(a) >=4: while n < 5: if g[n] == a[0]: = + 1 if g[n] == a[2]: = + 1 if g[n] == a[3]: = + 1 if g[n] == a[3]: = + 1 n = n + 1 return(am)
python python-3.3
No comments:
Post a Comment