Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 20 Online
OpenStudy (anonymous):

Is there a way to program "not" or "false"? For example, if x does not ==5:

OpenStudy (anonymous):

Do mean checking if {something is not something} OR {if something is false}

OpenStudy (anonymous):

i think i would mean if something is false, like the statement that x==5 is false in this example.

OpenStudy (anonymous):

There is many ways to do that, it all depends on the problem at hand. For example, if i wanted to see if x is 5, i would say. if (x == 5) { //The true state //Do something } else { //The false state //DO something }

OpenStudy (anonymous):

i'm working on ps1, the 1000th prime number. How do I tell the program when my division test proves false, that the number is actually prime, then it should follow the second set of parameters? I have tried the following (loosely) if a%b==0: procedure x else: procedure y When I try this, the IDLE highlights "else" and says it's an error in syntax.

OpenStudy (anonymous):

The syntax of your loose example is correct.

OpenStudy (anonymous):

if you wanted to see if x does not =5, and therefore is a prime number, you could say if a%b!=0: procedure y you can avoid the else clause this way, because your syntax looks correct.

OpenStudy (anonymous):

*even though your syntax looks correct

OpenStudy (anonymous):

what does the ! mean?

OpenStudy (anonymous):

if x != 5

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!