Looks like you have donne a step in right direction, but it is still more complicated.
When a guess match a code in correct position, you have to make sure the same guess will not be checked for wrong position and that same code will not be checked for wrong position either. And when a guess match a code for wrong position, you have to make sure you will not check that code again.
Advice: make guess an array just like code and arr, it open the door for loops and code size reduction once it works.
[Update]
Quote:
Could you please help me with doing so? I already have an arr but can't seem to use it to do so
you have created
arr
to prevent matching 2 times the same guess,
you need another array to prevent matching 2 times the same code.
- naming an array
arr
is a bad idea, since it is used to tag matched guess, you can name it
tag_guess
.
- create another array named
tag_code
and you use it to prevent marching 2 times the same code.
- Rather than using variables for each guess, use an array. It will make your code suited for use of loops (and code size reduction).
[Update]
Your code should look like:
if tag_guess[0]== False:
if guess[0]== code[1] and tag_code[1]== False:
tag_guess[0]== True
tag_code[1]== True
wronPlace= (wronPlace+1)