These are getting complex, is there an easy way to solve them?
Answer
It may not necessarily be an easy way, but some exercises that have always helped me and many others are described below, and work for any issue you come across on your programming journeys!
The rubber ducky method! You literally talk out loud to a rubber ducky, or anything else, or nothing at all like a crazy coder, and this act of talking out loud lets you hear your mistakes! It often helps to hear them verbally instead of in your head.
Good olâ pen and paper! Youâd be surprised how often a problem youâre having can be solved if you write it out step by step. Keeping each step of a problem correctly in your head is a difficult task, and becomes nearly impossible as you progress and do more difficult work.
With either method, always break down the problem into its simplest parts.
I felt the same way at first because i was just copying and pasting lol but for instance this is the way I broke it down after i looked at it better here is an example
and I will break down the first question here
Set bool_one equal to the result of
False or not True and True
You start with not. Not of True is False so your left with False or False and True after that you move to and False and True is False. so you are left with False or False. False or False is False so you have the answer of false
#And Flase or True not not
# not,and,or
#False or not True and True
#False false false
##Question False or not True and True
## You start with not. Not of True is False so your left with False or False and True after that you move to and False and True is False. so you are left with False or False. False or False is False so you have the answer of false
bool_one = False
#False and not True or True
#False false True
bool_two = True
#True and not (False or False
#False False
bool_three = True
#not not True or False and not True
#True or False and False
bool_four = True
#False or not True and True
bool_five = False
because and requires both conditions to be true. Only if both conditions are met, evaluate to true
this can be very handy for example for a login functionality. Only if the password and username match, log the user in. You donât want to login the user if only the password or the user name is correct
I was confused at first but it makes sense now.
I was trying to figure out what is even meant by the question:
Is âFalse or Trueâ = True? Ummm what?
I found that it helps to replace each False / True with an actual statement, so that youâre evaluating an âand/orâ statement to be true or false.
Example:
Right now my TV is actually off. Iâll replace âTrueâ with âTV is offâ. Iâll replace âFalseâ with âTV is Onâ.
The statement âFalse or Trueâ is now " âThe TV is ONâ or âThe TV is Offâ "
As a complete statement, this is obviously a true statement, because it IS âon or offâ.
The TV is either on or off? Yeah, it has to be one of those! Thatâs a true statement.
Now what about âFalse and Trueâ?
If you said " âThe TV is ONâ AND âThe TV is Offâ " that would be obviously False.
It canât be both on AND off, can it?
This explanation should be at the top - I remember AND OR NOT NAND NOR gates from basic programming hundreds of years ago, but for some reason my brain didnât activate the information until I read this comment. Thanks!
Edit: I meant myke_sâs comment FYI.
myke_s:
Right now my TV is actually off. Iâll replace âTrueâ with âTV is offâ. Iâll replace âFalseâ with âTV is Onâ.
The statement âFalse or Trueâ is now " âThe TV is ONâ or âThe TV is Offâ "
Not original poster, but I wanted to know if thereâs ever a reason to use not not? It seems like not not always cancels each other? So Iâm unsure in what situation we would ever use it.
Also, is there a reason why we have to solve the inner not and then the outer not? LIke couldnât I just say that not not cancels each other? Because the answer seems the same regardless.
Like for e.g. A not not True is evaluated as:
not not True becomes not False
and then not False becomes True
but is it not correct if I just say off the bat that not not cancels each other? If I see a not not, shouldnât I just assume it cancels each other so I could safely ignore it from the equation? So if I saw not not True, I would assume the not not is irrelevant, since the answer would still be the original boolean value (True) regardless.
Casting⌠roughly means to convert something to another type yes?
So what youâre saying is that I can use not not to change certain results into a boolean. Is it safe to assume that it changes any result into a boolean?
Also, thank you for replying to my original post! I replied to this late, but I appreciate the help. Never knew you could do that with not not.