Posts

Showing posts with the label boolean

How do I get the opposite (negation) of a Boolean in Python?

How do I get the opposite (negation) of a Boolean in Python? For the following sample: def fuctionName(int, bool): if int in range(...): if bool == True: return False else: return True Is there any way to skip the second if-statement? Just to tell the computer to return the opposite of the boolean bool ? bool This is probably just pseudocode, but int and bool are both builtin names (for the types they represent), and should not be used as variable names. – SingleNegationElimination Aug 11 '11 at 18:19 int bool yes, it's just a pseudo-code ,, demonstration purposes only... – amyassin Aug 11 '11 at 18:26 ...

this method must return a result of type boolean, java

this method must return a result of type boolean, java public boolean Winner() { for (int z = 0; z < 3; z++) { if (board[z] != null && board[z] == board[z+3] && board[z] == board[z+6] ) { return true; } } for(int i=0; i<7;i+=3){ if (board[i] != null && board[i] == board[i+1] && board[i] == board[i+2]) { return true;} } } It returns me this error: this method must return a result of type boolean. What am I doing wrong? 5 Answers 5 Right now, the function isn't guaranteed to return a boolean , because it's possible that neither of the if statements will ever be entered. boolean if You could fix it like this (but only do this if it's actually what your logic needs!): public boolean Winner() { for (int z = 0; z < 3; z++) { if (board[z] != null ...