Jump to content

Python Not Operator

ColdDigital
Go to solution Solved by spenser_l,

If you're not sure about the answers, you can always just execute the program to see the results. I've done so in Java just for peace of mind and will explain each of the tests. For simplicity in Java I've just put the result of the exponent parts.

public class Test {

	public static void main(String[] args) {
		
		boolean test[] = new boolean[5];
		
		test[0] = !true;
	
		test[1] = !(81 < 64);
		
		test[2] = !(10 % 3 <= 10 % 2);
		
		test[3] = !((9 + 16) != 25);
		
		test[4] = !!false;
		
		for (boolean b : test) {
			System.out.println(b);
		}
		// results:
		// 1. false
		// 2. true
		// 3. true
		// 4. true
		// 5. false
	}
}

1. not True: not (or ! in Java) just means the opposite of whatever the result is, so False.

2. not (81 < 64): 81 is NOT less than 64, so that expression results in False. So not False is True.

3. not (10 % 3 <= 10 % 2): 10 mod 3  = 1, 10 mod 2 = 0. So 1 <= 0 is False, and not False is True.

4. not ((9 + 16) != 25): 9 + 16 = 25 != 25. Well 25 IS equal to 25, so the expression is False, and not False is True.

5. not not False: again, think of it like this: not (not False) = not True = False.

Feel free to ask if any of this is unclear.

Hey,

Im doing python right now on codecademy, and am on the Operator section. I understand everything so far but once I got to the Not operators I somewhat lost the understanding.

Basically its asking me if these are not true (false) or not false (true), are these answers correct?

bool_one = not True  -- False

bool_two = not 3**4 < 4**3  -- False , 81 is greater than 64 

bool_three = not 10 % 3 <= 10 % 2 --  True, 3 remainder 1 is not equal to or less than 5

bool_four = not 3**2 + 4**2 != 5**2 False, 25 is equal to 25

bool_five =  not not False -- wt* does this mean? 

Thanks

<-----><-----><-----><-----><-----><-----><-----><-----><-----><----->

                                         Cold

Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, ColdDigital said:

bool_five =  not not False -- wt* does this mean?

false I assume. double negative, I'm not 100% sure tho I've never really done this stuff before. 

CPU: Intel 3570 GPUs: Nvidia GTX 660Ti Case: Fractal design Define R4  Storage: 1TB WD Caviar Black & 240GB Hyper X 3k SSD Sound: Custom One Pros Keyboard: Ducky Shine 4 Mouse: Logitech G500

 

Link to comment
Share on other sites

Link to post
Share on other sites

1 is right

2 is actually true, because (3**4 < 4**3) returns false, and "not" reverses that 

3 and 4 you can probably solve by yourself based on what i said about 2

5 if not false is true, then not not false would be _______

i think thats how it works, i havent done python for a few years...

NEW PC build: Blank Heaven   minimalist white and black PC     Old S340 build log "White Heaven"        The "LIGHTCANON" flashlight build log        Project AntiRoll (prototype)        Custom speaker project

Spoiler

Ryzen 3950X | AMD Vega Frontier Edition | ASUS X570 Pro WS | Corsair Vengeance LPX 64GB | NZXT H500 | Seasonic Prime Fanless TX-700 | Custom loop | Coolermaster SK630 White | Logitech MX Master 2S | Samsung 980 Pro 1TB + 970 Pro 512GB | Samsung 58" 4k TV | Scarlett 2i4 | 2x AT2020

 

Link to comment
Share on other sites

Link to post
Share on other sites

You can think of it like this:

not (not False) = not (True) = False

CPU: i7-4790K --- HEATSINK: NZXT Kraken X61 --- MOBO: Asus Z97-A --- GPU: GTX 970 Strix --- RAM: 16GB ADATA XPG --- SSD: 512GB MX100 | 256GB BX200 HDD: 1TB WD Black --- PSU: EVGA SuperNova G2 --- CASE: NZXT H440 --- DISPLAY3 x Dell U2414H --- KEYBOARD: Pok3r (Clears) --- MOUSE: Logitech G Pro --- OS: Windows 10

Link to comment
Share on other sites

Link to post
Share on other sites

If you're not sure about the answers, you can always just execute the program to see the results. I've done so in Java just for peace of mind and will explain each of the tests. For simplicity in Java I've just put the result of the exponent parts.

public class Test {

	public static void main(String[] args) {
		
		boolean test[] = new boolean[5];
		
		test[0] = !true;
	
		test[1] = !(81 < 64);
		
		test[2] = !(10 % 3 <= 10 % 2);
		
		test[3] = !((9 + 16) != 25);
		
		test[4] = !!false;
		
		for (boolean b : test) {
			System.out.println(b);
		}
		// results:
		// 1. false
		// 2. true
		// 3. true
		// 4. true
		// 5. false
	}
}

1. not True: not (or ! in Java) just means the opposite of whatever the result is, so False.

2. not (81 < 64): 81 is NOT less than 64, so that expression results in False. So not False is True.

3. not (10 % 3 <= 10 % 2): 10 mod 3  = 1, 10 mod 2 = 0. So 1 <= 0 is False, and not False is True.

4. not ((9 + 16) != 25): 9 + 16 = 25 != 25. Well 25 IS equal to 25, so the expression is False, and not False is True.

5. not not False: again, think of it like this: not (not False) = not True = False.

Feel free to ask if any of this is unclear.

CPU: i7-4790K --- HEATSINK: NZXT Kraken X61 --- MOBO: Asus Z97-A --- GPU: GTX 970 Strix --- RAM: 16GB ADATA XPG --- SSD: 512GB MX100 | 256GB BX200 HDD: 1TB WD Black --- PSU: EVGA SuperNova G2 --- CASE: NZXT H440 --- DISPLAY3 x Dell U2414H --- KEYBOARD: Pok3r (Clears) --- MOUSE: Logitech G Pro --- OS: Windows 10

Link to comment
Share on other sites

Link to post
Share on other sites

26 minutes ago, Enderman said:

1 is right

2 is actually true, because (3**4 < 4**3) returns false, and "not" reverses that 

3 and 4 you can probably solve by yourself based on what i said about 2

5 if not false is true, then not not false would be _______

i think thats how it works, i havent done python for a few years...

bool_two = not 3**4 < 4**3  -- True: 81 is not less than 64, its greater. Meaning it would be false but cause of the not its True. That how I understood it from your explanation.

bool_three = not 10 % 3 <= 10 % 2 --  3 remainder 1 is less than or equal to 5, it will take the true value being: 3 remainder 1 being less than 5. This would make it True, cause of the not it makes it false. 

bool_four = not 3**2 + 4**2 != 5**2 -- 25 is equal to 25, so its false, cause of not in front of the statement, its True. 

bool_five =  not not false, not false = True, not true  = False , so False

Edit: Nvm, messed up boolean_three, know why only asked for the remainders.

so bool_three would be true: bool_three = not 10 % 3 <= 10 % 2 --  10 % 3 has 1 remainder, 10  % 2 has 0 remainders. 1 <= 0, equals false, because of not its true, in other words not false = True

Hope its correct now. If it is thanks a bunch! Found these Not operators a complete mind f**k

<-----><-----><-----><-----><-----><-----><-----><-----><-----><----->

                                         Cold

Link to comment
Share on other sites

Link to post
Share on other sites

10 minutes ago, spenser_l said:

If you're not sure about the answers, you can always just execute the program to see the results. I've done so in Java just for peace of mind and will explain each of the tests. For simplicity in Java I've just put the result of the exponent parts.


public class Test {

	public static void main(String[] args) {
		
		boolean test[] = new boolean[5];
		
		test[0] = !true;
	
		test[1] = !(81 < 64);
		
		test[2] = !(10 % 3 <= 10 % 2);
		
		test[3] = !((9 + 16) != 25);
		
		test[4] = !!false;
		
		for (boolean b : test) {
			System.out.println(b);
		}
		// results:
		// 1. false
		// 2. true
		// 3. true
		// 4. true
		// 5. false
	}
}

1. not True: not (or ! in Java) just means the opposite of whatever the result is, so False.

2. not (81 < 64): 81 is NOT less than 64, so that expression results in False. So not False is True.

3. not (10 % 3 <= 10 % 2): 10 mod 3  = 1, 10 mod 2 = 0. So 1 <= 0 is False, and not False is True.

4. not ((9 + 16) != 25): 9 + 16 = 25 != 25. Well 25 IS equal to 25, so the expression is False, and not False is True.

5. not not False: again, think of it like this: not (not False) = not True = False.

Feel free to ask if any of this is unclear.

I see what I did wrong on number 3, I did the whole division, it asked me instead to only solve how many remainders would be left in each expression. Its clear now after I looked at your java comment, thanks man appreciate your help!

<-----><-----><-----><-----><-----><-----><-----><-----><-----><----->

                                         Cold

Link to comment
Share on other sites

Link to post
Share on other sites

It helps to understand operator precedence (link to the Python docs).

Let's apply operator precedence to one of the questions

bool_two = not 3**4 < 4**3

So according to the order of operations, exponentiation is applied first.

bool_two = not 81 < 64

So we only have two operations left. The less than, and the not. The less than operator gets applied next.

bool_two = not False

And finally the not operator is applied.

bool_two = True

 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×