Mock test

105 views
Skip to first unread message

Palak Sinha

unread,
Nov 21, 2020, 4:33:22 AM11/21/20
to Discussion forum for Computational Thinking
Can someone please explain this??
IMG_20201121_145828.jpg
IMG_20201121_145920.jpg

Anand Iyer

unread,
Nov 21, 2020, 4:55:52 AM11/21/20
to Discussion forum for Computational Thinking, Palak Sinha
I just answered the same question in another post.  

Yes, the solution in the pdf is right.  

What happens here is a little weird, but it works...will try explaining.

Consider two persons.  Following are the marks they got in Physics, Chemistry, Maths, and the total.

Person1: 40 (Physics), 40 (Physics), 70 (Maths), 150 (Total)
Person2: 30 (Physics), 10 (Chemistry), 50 (Maths), 90 (Total)

As the code stands now, Proc2 will return -10 (30 - 40) for Physics, -30 (10 - 40) for Physics, -20 (50 - 70) for Physics and -60 (90 - 150) for the Total.

It will add the first 3 to get -10 + - 30 + -20 = -60.  THis matches with the difference in the Total, and hence Z is incremented.  

It works as expected.

Now, if we change line 20 as follows:

if (C > D) {
  return C - D
}

it would return +10, +30, +40, +60.  In this case, the sum of the first 3 should match with the Total, and hence Z incremented.

Why would you want to change a line unnecessarily, if both worked well?  THat's the reason, line 20 is not an error.







On Saturday, November 21, 2020 at 3:03:22 PM UTC+5:30 Palak Sinha wrote:
Can someone please explain this??

Palak Sinha

unread,
Nov 21, 2020, 5:03:20 AM11/21/20
to Anand Iyer, Discussion forum for Computational Thinking
Thank you for the clarification. 

Anand Iyer

unread,
Nov 21, 2020, 5:13:34 AM11/21/20
to Palak Sinha, Discussion forum for Computational Thinking
I just realised I made so many mistyping and  typed out ‘physics’ when I intended to type chemistry and maths.   Bad copy-paste problems😀

But I hope the reader got the idea..
--
Cheers,

Palak Sinha

unread,
Nov 21, 2020, 5:17:14 AM11/21/20
to Anand Iyer, Discussion forum for Computational Thinking
Yes, but I got it. Thanks

Computational Thinking Support 2

unread,
Nov 21, 2020, 10:40:24 AM11/21/20
to Discussion forum for Computational Thinking, Palak Sinha, Discussion forum for Computational Thinking, anandd...@gmail.com
What Anand explained is correct. Solution document is correct.

Regards,
Nijin
IITM Online Degree Programme

Reply all
Reply to author
Forward
0 new messages