Doubt in Q7 mock test

217 views
Skip to first unread message

Shrishti Hegde

unread,
Nov 12, 2020, 11:15:37 PM11/12/20
to Discussion forum for Computational Thinking
Dear Sir/Ma'am ,

Greetings!

Could you please help with how to get the answer for Q7 in the mock test.
In the solution, the condition is as follows: 
if ((A and B)==False and (A or B)==True){
return (True)
}
else{
         return (False)
}
The above condition will never get satisfied, because if both A and B are False it is obviously not possible that either of the two will be True and hence the code will always return the value as 'False".
It would be great if you could correct me if I'm wrong and provide me with an explanation for the answer        

DHARMA TEJA GODUMALA

unread,
Nov 12, 2020, 11:35:00 PM11/12/20
to Discussion forum for Computational Thinking, Shrishti Hegde
And Condition
X-True and Y true= then only the whole condition will be executed otherwise it is not
If anyone of them is false then the statement won't get executed

Or Condition
X-False or Y False = Then only the whole condition won't get executed in remaining all cases it gets executed.

if ((A and B)==False and (A or B)==True){
return (True)
}
else{
         return (False)
Now in the above 
Case 1.   A  is True ,B is False the condition(if ((A and B)==False and (A or B)==True) )gets executed and return True.
Case 2.   A is False, B is True the condition(if ((A and B)==False and (A or B)==True) )gets executed and return True.
Any one of X.year == Y.year , X.Genre== Y.genre is true and other is false then the code should be executed.

MANMAY SINGH

unread,
Nov 12, 2020, 11:52:44 PM11/12/20
to Discussion forum for Computational Thinking, DHARMA TEJA GODUMALA, Shrishti Hegde
Hey, Dharma I have a doubt.
In case 1:
we have A = True and B = False
So, in my opinion the statement "(A and B) == False" will be False as both the values A and B should be false to make it a True.
Therefore in this statement "if ((A and B)==False and (A or B)==True" we have two things which are separated by "and" which means that both the
condition should be true to execute the code.
i.e. first condition: (A and B)==False
second condition: (A or B)==True
So, to execute the code both the above condition should be true.
But what we saw that the first condition will return false and the second condition will true which makes it clear the the 'if' condition will not be executed.

Kindly clear my doubt.

DHARMA TEJA GODUMALA

unread,
Nov 13, 2020, 12:26:27 AM11/13/20
to Discussion forum for Computational Thinking, manmay...@gmail.com, DHARMA TEJA GODUMALA, Shrishti Hegde
Case 1 
we have A = True and B = False 
first condition: if((A and B)==False) then this will be true, it won't be false because (False==False is true)
second Condition if( (A or B)==True) then this will be true, it won,t be false because (True== True is true)
So both will be true 

Hope it helps you

Shrishti Hegde

unread,
Nov 13, 2020, 12:28:32 AM11/13/20
to Discussion forum for Computational Thinking, manmay...@gmail.com, DHARMA TEJA GODUMALA, Shrishti Hegde
Yes, Mr. Manmay, I agree with you. I had the same doubt. You explained it better than I did. Thank you very much!

MANMAY SINGH

unread,
Nov 13, 2020, 12:41:40 AM11/13/20
to Shrishti Hegde, Discussion forum for Computational Thinking, DHARMA TEJA GODUMALA
See, Dharma. I totally agree with you on this (False==False is true).
But in the first condition "(A and B)==False" will only return True if both A = False and B = False.
But we are given that A = True and B = False.(you can see Case 1 in your explanation in reply to Shrishti.)
--
Manmay Singh_._._._._

DHARMA TEJA GODUMALA

unread,
Nov 13, 2020, 12:42:07 AM11/13/20
to Discussion forum for Computational Thinking, hegde.sh...@gmail.com, manmay...@gmail.com, DHARMA TEJA GODUMALA
if(False== False) condition is equal as If (True).

I hope now you will get it clearly.

DHARMA TEJA GODUMALA

unread,
Nov 13, 2020, 12:51:37 AM11/13/20
to Discussion forum for Computational Thinking, DHARMA TEJA GODUMALA, hegde.sh...@gmail.com, manmay...@gmail.com
((True and False)== False)  is a True Condition.
For And Condition to make it true both A should be True,B Should be True in remaining all case it is false.

Message has been deleted

MANMAY SINGH

unread,
Nov 13, 2020, 1:17:01 AM11/13/20
to Discussion forum for Computational Thinking, DHARMA TEJA GODUMALA, hegde.sh...@gmail.com, MANMAY SINGH
Okay, now I have another doubt in your explanation. 
Here, the sign '==' is used for the equality.
And here it is being used as "A and B" that means we need to see both the value 'A' and 'B' equal to False.
I come up to this conclusion that if somewhere it is written "X.maths == 90" then we will look for the marks in maths for the card X exactly equal to 90.
And if it is written as "X.maths and X.physics == 90" then we will look for the marks in maths and physics both to be exactly equal to 90.

See I need the result on this with explanation:
1. A = False
    B = False 
then,  A and B == ?

2. A = True
    B = False
then,  A and B == ?

By the way thanks for taking part in the discussion and replying

DHARMA TEJA GODUMALA

unread,
Nov 13, 2020, 1:22:00 AM11/13/20
to Discussion forum for Computational Thinking, manmay...@gmail.com, DHARMA TEJA GODUMALA, hegde.sh...@gmail.com
Always the below mentioned conditions will be True.
And Condition
False and False= False
False and True= False
True and False= False
True and True = True

Or Condition
False or False= False
False and True= True
True and False= True
True and True= True

Hope it helps you

DHARMA TEJA GODUMALA

unread,
Nov 13, 2020, 1:25:44 AM11/13/20
to Discussion forum for Computational Thinking, DHARMA TEJA GODUMALA, manmay...@gmail.com, hegde.sh...@gmail.com
Sorry typing mistake in above the message
And Condition
False and False= False
False and True= False
True and False= False
True and True = True

 In Or condition
False or False= False
False or True= True
True or False= True
True or True= True

Hope it helps you

MANMAY SINGH

unread,
Nov 13, 2020, 1:33:39 AM11/13/20
to Discussion forum for Computational Thinking, DHARMA TEJA GODUMALA, MANMAY SINGH, hegde.sh...@gmail.com
Totally agree with you.

But let me think for some time because what I want to ask is taking longer than expected in typing.
So, wait I am asking my doubt.

MANMAY SINGH

unread,
Nov 13, 2020, 1:46:04 AM11/13/20
to Discussion forum for Computational Thinking, MANMAY SINGH, DHARMA TEJA GODUMALA, hegde.sh...@gmail.com

To be precise, we have two types of situation here:

1.   If (X and Y)

2.   (P and Q) ==

In the first situation we have to check whether both X and Y is true or not. If both are true then the code will execute and if both are false then the code will not get executed.

But in the second situation we are marking the values of P and Q to be exactly something.

 

The key difference between situation 1 and 2 is that in 1 we have ‘if’ and in 2 we have ‘==’.

And in ‘if’ we want conditions to be true but in ‘==’ we want conditions to be exact of some value.

 

So, regarding the question in Mock Test we have

In place of X:  “(A and B) == False”

In place of Y:  “(A or B) == True”

In place of P: A

In place of Q: B

Just tell me if I am right or wrong. If I am wrong what are those points.

MANMAY SINGH

unread,
Nov 13, 2020, 2:02:39 AM11/13/20
to Discussion forum for Computational Thinking, MANMAY SINGH, DHARMA TEJA GODUMALA, hegde.sh...@gmail.com
Okay, this is what exactly I want to ask:

If it is given that “A = True and B = False” what is the difference between:

1.  If (A and B == False)

2.  A and B == False

3.  If (A and B)


MANMAY SINGH

unread,
Nov 13, 2020, 2:12:21 AM11/13/20
to Discussion forum for Computational Thinking, MANMAY SINGH, DHARMA TEJA GODUMALA, hegde.sh...@gmail.com
Is there any difference between:

1. if (A and B == 90)
2. if (A == 90 and B == 90)

MANMAY SINGH

unread,
Nov 13, 2020, 2:14:26 AM11/13/20
to Discussion forum for Computational Thinking, MANMAY SINGH, DHARMA TEJA GODUMALA, hegde.sh...@gmail.com
3. if ((A and B) == 90)

DHARMA TEJA GODUMALA

unread,
Nov 13, 2020, 2:15:55 AM11/13/20
to Discussion forum for Computational Thinking, manmay...@gmail.com, DHARMA TEJA GODUMALA, hegde.sh...@gmail.com
Case 1 
A= True ,B= False
X:  "(True and False)==False"  then X will be "True", because false==false
case 2 
A= True ,B= True
X: "(True and True)==False" then X will be false ,because True != False

Main Condition :   "if ((A and B)==False and (A or B)==True)"  
so put the case 1 in above Main condition
if((True and False)== False and (True or False)==True)
the above condition will now be reduced to if((false ==false and True ==True) and it further reduces to if (True and True) and it reduces further to if(True).

Now put case 2 in our main condition
if((True and True)==False and (True or True)==True)
the above condition will now be reduced to if((True==False and True== True) and it further reduces to if (False and True) and further reduces to if(False).

Hope it clears your doubt.

DHARMA TEJA GODUMALA

unread,
Nov 13, 2020, 2:27:46 AM11/13/20
to MANMAY SINGH, cs1001-...@nptel.iitm.ac.in, hegde.sh...@gmail.com
1. If (True and False==False) is further reduced to If( True and True) and it is further reduced to If (True) then you will enter into the loop.
2. True and False==Flase is reduced to True and True and it is further reduced to True.
3. If (True and False) is further reduced to IF(False) 

Antony

unread,
Nov 13, 2020, 11:23:52 AM11/13/20
to Discussion forum for Computational Thinking, DHARMA TEJA GODUMALA, manmay...@gmail.com, hegde.sh...@gmail.com
1. if (A and B == 90)
2. if (A == 90 and B == 90)
3. if ((A and B) == 90)

First of all, I think you are probably overthinking this. What you are trying to do in your various statements is mix boolean variables (A and B which holds only TRUE or FALSE) with a number.
Common behavior for most programming languages would be to treat a non zero integer to be "FALSE".  Again, this is subjective to the programming language.
So if A = TRUE, then  "A and  0"  might give you  FALSE,  "A and  1"  might give you  TRUE . But at the same time, if you try to do "A == 1" , that might give you FALSE.
I think your 1 and 2 might throw syntax error in most cases, because of missing parenthesis. 3 might return TRUE , if A and B are both TRUE.  

Malabika Guha Mustafi

unread,
Nov 13, 2020, 12:39:01 PM11/13/20
to Discussion forum for Computational Thinking, Antony, DHARMA TEJA GODUMALA, manmay...@gmail.com, hegde.sh...@gmail.com
Let X and Y be two rows in the “Library” table. We call books X and Y compatible if either published in the same year or the same genre but not both. Let CompatiblePair(X, Y) be a procedure to find whether X and Y are compatible. Choose the correct implementation of the procedure CompatiblePair.

I approach the problem in very simple way.
option 1) A or B true then return true(  but it may be true for both true since OR operation so it is discarded.)
option2) Again OR option between  Year and Genre( so it may be true for both true  so it is discarded)
option 3) same logic OR operation between ( (A and B)=false OR ( A OR B)=true,) still the option is open when A and B both true .
option 4) And operator so (A OR B= true and (A AND B )= false )implies A and B can not be both true.

Is it Ok?

AC

unread,
Nov 13, 2020, 12:53:58 PM11/13/20
to Discussion forum for Computational Thinking, Malabika Guha Mustafi, Antony, DHARMA TEJA GODUMALA, manmay...@gmail.com, hegde.sh...@gmail.com

Hi,

I apologize for chiming in without reading the entire discussion thread:

I answered correctly for Q7 and this is how I interpreted the following psuedo-code block:

 113.png

 

My interpretation:

1. (A and B) == False means : if the 2 conditions "A is TRUE" AND "B is True" - Both  conditions- turn out to be FALSE. This can happen iff either A is true OR B is true, but NOT while both A and B is TRUE (at the same time). 'Çause in that case (A and B) then would be == TRUE. Right?

2.  (A OR B) == True means : if either the condition "A is TRUE" OR the condition "B is True" - any one turns out to be TRUE.

3. So this checks out what is asked in the question (exclusive OR condition) - if either is true but not BOTH, type of a scenario.

Best.
Message has been deleted

MANMAY SINGH

unread,
Nov 13, 2020, 1:31:56 PM11/13/20
to Discussion forum for Computational Thinking, AC, Malabika Guha Mustafi, Antony, DHARMA TEJA GODUMALA, MANMAY SINGH, hegde.sh...@gmail.com
Guys, just loved the way you all explained. Simply amazing. Now, this forum truly makes sense to clear doubts.
Absolutely amazing. 

Now, I will try to put my all efforts to clear the Qualifier so that I would be a part of this community.

Thanks guys.

Srinath Sai

unread,
Nov 13, 2020, 3:56:44 PM11/13/20
to Discussion forum for Computational Thinking, manmay...@gmail.com, AC, Malabika Guha Mustafi, Antony, DHARMA TEJA GODUMALA, hegde.sh...@gmail.com
Listing the four combinations below:

(1) X.Year == Y.Year and X.Genre == Y.Genre
(2) X.YEAR == Y.Year and X.Genre ≠≠ Y.Genre
(3)X.YEAR ≠≠ Y.Year and X.Genre == Y.Genre
(4)X.YEAR ≠≠ Y.Year and X.Genre  ≠≠  Y.Genre

Option 1 is wrong: A or B means combinations (1), (2), and (3). which is wrong as it includes (1) also, which means both, while the problem asks to consider only either or and not both.
,
Option 2 is wrong: As, here again, A or B means combinations (1),(2), and (3). which is wrong as it includes (1) which means both, while the problem asks to consider only either or and not both.

Option 3 is wrong: A and B False excluding Option (1) the rest of the combinations, i.e., (2),(3),(4); 
                                 A or B true means the combinations (1),(2),(3)
(A and B false) OR (A or B True) is an OR statement, and so, we take the Union of the above, 
i.e., {(2),(3),(4)} {(1),(2),(3)} which gives the result {(1),(2),(3),(4)} which is wrong, as going by the question (1) and (4) can't be considered.

Option 4:  A and B false means, (2)(3)(4); 
                              A or B true means (1),(2),(3)
(A and B false) AND (A or B True) is an AND statement, and so, we take the Intersection of the above.
i.e., {(2),(3),(4)}   {(1),(2),(3)}  which is (2), (3).

(2) and (3) are the two possibilities that have either the 'same year' or the 'same genre', and this matches with what is stated in the question.
So, Option 4 is correct.

Reply all
Reply to author
Forward
0 new messages