Is there a way to simplify this if-statement:
if self[by1,bx1]=='A' or self[by1,bx1+1]=='A' or self[by1,bx1+2]=='A' or self[by1,bx1+3]=='A':
coming from a class where self[y,x] fetch a data in a table.
The original code is:
for i in range(4):
if self[by1,bx1]=='A' or self[by1,bx1+1]=='A' or self[by1,bx1+2]=='A' or self[by1,bx1+3]=='A':
print('There is already a ship here')
by1=0
bx1=0
self.placing_Battleship_p1()
elif by1==0 or by1==0:
pass
else:
self[by1,bx1+i]='B'
I want it to check if every position of my table are not equal to 'A' before changing them for a 'B'.
Sure, you could use any for this. This should be equivalent.
if any(self[by1,bx1+x]=='A' for x in range(4)):
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With