Graded-3_Q.13

187 views
Skip to first unread message

_Music_Viking

unread,
Nov 2, 2020, 1:44:04 PM11/2/20
to Discussion forum for Computational Thinking
How is the answer '2'? And why is it accepted only as string and not an integer?
Anyways, I think the answer should be '0'.
Can anyone please help me with this?

Priyanshu Singh

unread,
Nov 2, 2020, 1:49:47 PM11/2/20
to Discussion forum for Computational Thinking, _Music_Viking
i have same doubt a is passed as r in the aegument and A is initialised 0 and   in the argument 'if' =r+1 and 'else' is r so eithr a will be  1 for if=true and a will be 0  for  else=true and here else is satsifer,then why isnt a=0,how can it even be more than 1

Aritra Roy

unread,
Nov 2, 2020, 2:49:49 PM11/2/20
to Discussion forum for Computational Thinking, priyanshu...@gmail.com, _Music_Viking
The answer is 2 indeed. The problem was really complex and hence, it's too cumbersome to write down the logic here. I copied the words.pdf data and pasted it on excel [after all, in Stat. they taught us google sheets and its associated formulae so that our complex calculations of tables get easier]. And, then solved it finally.

satya takkellapati

unread,
Nov 2, 2020, 9:06:28 PM11/2/20
to Discussion forum for Computational Thinking, _Music_Viking
addword is simply adding the letter count to sum and count is keeping track of the number of words....so by the end of first while loop we will have the total lettercount of the complete dataset and count will give us the number of words and B would simply be this sum/count which is nothing but the average word length of our data set 
now after initializing the values to 0 and moving T2 to T1 we will perform the next while loop. In this loop, we are performing the AddWord procedure till we get a full stop. In other words, we are simply counting the total letter count of a sentence and the number of words in it, and when we get " . " we stop, enter the if loop compute the average word length of that sentence, and store it in C. After that we will perform procedure DoSomething(C, B, A) and check if C<B to put it simply we are checking if the average word length of that sentence is less than the avg word length of the entire data set. If so we increment A and return the updated  value of A else we simply return A  

Laxmi Priya Kasi

unread,
Nov 2, 2020, 9:48:29 PM11/2/20
to Discussion forum for Computational Thinking, priyanshu...@gmail.com, _Music_Viking
I agree. I have got the answer as 0 as well. The values of P(i.e. C) is always greater than the Q(i.e. B) value so the condition P<Q doesn't satisfy and R(i.e.A) is not incremented. This is how I got it. Please do clarify.

satya takkellapati

unread,
Nov 2, 2020, 9:59:14 PM11/2/20
to Discussion forum for Computational Thinking, Laxmi Priya Kasi
C is the avg word length of a sentence
B is the avg word length of the entire dataset
If you calculate for all the sentences you will find that the avg length of two sentences is less than the avg length of the dataset

Sagar kashyap

unread,
Nov 2, 2020, 10:06:42 PM11/2/20
to satya takkellapati, Discussion forum for Computational Thinking, Laxmi Priya Kasi
Bro what you want to say?
Is this ans is '0' or not

--
You received this message because you are subscribed to a topic in the Google Groups "Discussion forum for Computational Thinking" group.
To unsubscribe from this topic, visit https://groups.google.com/a/nptel.iitm.ac.in/d/topic/cs1001-discuss/j5L4Ii0qxXE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cs1001-discus...@nptel.iitm.ac.in.
To view this discussion on the web visit https://groups.google.com/a/nptel.iitm.ac.in/d/msgid/cs1001-discuss/64ca163a-e279-49a4-b506-d9727076814dn%40nptel.iitm.ac.in.

Nikhil Gupta

unread,
Nov 3, 2020, 12:53:36 AM11/3/20
to Discussion forum for Computational Thinking, Laxmi Priya Kasi, priyanshu...@gmail.com, _Music_Viking

There are total 2 while loop in this question. In the first while loop, after all the iteration, Sum and Count will take value as 329 and 65 respectively. This was already calculated in Lecture 3.3 at 5:02 minutes. So B becomes 329/65 = 5.0615. In the second while loop, the Sum and Count is calculated until first word with a full stop is encountered, i.e. a sentence ending. If a sentence ending is encountered, then DoSomething procedure is called in which parameters C,B and A takes the average letter count of sentence and average letter count of all words (5.0615) and 0 initially respectively. A is incremented only if C < B, ie if average letter count of a sentence is less than the average letter count of all words. There are total 5 sentences and only 2 sentences  (for sentence 1, B=4.5 and sentence 4, B = 4.67) satisfy the condition. So A is incremented only 2 times and takes the final value as 2.

Anand Iyer

unread,
Nov 3, 2020, 4:11:04 AM11/3/20
to Discussion forum for Computational Thinking, Nikhil Gupta, Laxmi Priya Kasi, priyanshu...@gmail.com, _Music_Viking

Aritra Roy

unread,
Nov 3, 2020, 4:44:22 AM11/3/20
to Discussion forum for Computational Thinking, anandd...@gmail.com, Nikhil Gupta, Laxmi Priya Kasi, priyanshu...@gmail.com, _Music_Viking
The correct answer is 2 indeed and fortunately, I got this one right despite the level of complexity in the question. I copied words.pdf data into excel sheet to make things simple. To put it simply :-
The program checks if average letter count per sentence is less than [A increments by 1] or greater than [A returns 0 i.e. value of A doesn't change] the average letter count of the entire paragraph which is C= 5.06
Now there are 5 sentences in the passage whose average word lengths are 4.5, 5.14, 6.25, 4.67, 5.08 respectively.
As you see out of these 5 values, only 4.5 and 4.67 are the values which are less than 5.06
That's how A increments by 1 twice and A==2 finally.
Reply all
Reply to author
Forward
0 new messages