I seem to be having an issue pythons.format() tool. I currently have this code:
varno=6
input=product([True,False],repeat = (varno))
string= ({1} or not {2} or not {5} )and (not {1} or {6} )and (not {2} or not {3} )and ({3} or not {4} )and (not {4} or {5} or not {6} )
for i in input:
print(i) //prints (True, True, True, True, True, True)
ans=(string.format(*i))
and It returns this error
ans=(string.format(*i))
IndexError: Replacement index 6 out of range for positional args tuple
even though there are 6 values in i, so 6 should not be out of range. I have no idea what is going wrong or how to fix it. Any help would be greatly appreciated.
indexes of a list run from 0 to n-1, so the last item in your 6 item list would have an index =5, and the first item in your list would have an index =0
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.