Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+9 votes

hey guys,
im working on a personal project, and i was looking for some help online and i came across some examples online that add "and not" inside the if statements, if anyone is familir with this, could you please let me know hen do i have to add them?

asked in CSC201 Spring 2021 by (1 point)
edited by
+2

Yeah! We would love to see what you've been working on :)

+1

i am currently working on pathfinding algorithms, the A* one to be more specific :)

3 Answers

+4 votes
answered by (1 point)
+3 votes

I'm not familiar with 'and not' statements. Could you mean just the 'not' method is a logical operator in python so if you used to return objects that would be true if the expression would be false. The 'and' part of the statement is just defining what the operator should return just like we learned about with 'or', and 'and' statements.

for e.x:

x = 6
if  not x > 6:
   print ('true')
else:
   print('false')
>>> true

This code returns true because although x = 6 is not greater than the numerical value defined in the if statements, the 'not' operator changed the false return to true. If you removed the 'not' operator the code would run normally returning false.

x = 6
if x > 6:
     print ('true')
else:
     print ('false')
>>> false

I hope this helps and answers your question because again I've never experienced 'and not' statements just 'not' statements.

answered by (1 point)
+2 votes

Hey Adam, can you please be more specific on what project you are working on and the help you are seeking?

answered by (1 point)
+1

not looking for any specific help, i was just asking about the if statement thing, dm me I'll tell you the details

...