doubt

63 views
Skip to first unread message

R. NITHYA NITHYA

unread,
Nov 20, 2020, 5:41:36 AM11/20/20
to Discussion forum for Computational Thinking
can anyone please tell me how to put this sum ie, graded assignment 3 last qn. please pls...

Computational Thinking Support 2

unread,
Nov 20, 2020, 6:24:28 AM11/20/20
to Discussion forum for Computational Thinking, R. NITHYA NITHYA
Hi,
Can you please tell more about your doubt? I couldn't get your doubt.
BTW, you can go through the pdf solution also. You can also ask in the today's live session (6 - 8)pm.

Regards,
Deepak
IITM Online Degree team

Srinath Sai

unread,
Nov 20, 2020, 2:55:24 PM11/20/20
to Discussion forum for Computational Thinking, ct-su...@onlinedegree.iitm.ac.in, R. NITHYA NITHYA

Srinath Sai

unread,
Nov 20, 2020, 3:51:39 PM11/20/20
to Discussion forum for Computational Thinking, Srinath Sai, ct-su...@onlinedegree.iitm.ac.in, R. NITHYA NITHYA

The first while loop calculates the value of B using the procedure AddWord.

Sum of letter count of all the words/ Total number of words = 329/65. So, B = 5.077 (approx.)

Just before entering the IF loop of (X. Word ends with a full stop) in the second while loop, the PROCEDURE Sum, Count= AddWord (X, Sum, Count) will calculate and store the Sum value to be the sum of letter count up to the penultimate word in a sentence and the Count value to be the total number of words up to the penultimate word in a sentence, respectively.

Once the last word of every sentence gets picked up, we enter the IF loop as the condition (X.Word ends with a full stop) becomes true and inside this loop, the value of C for the particular sentence is calculated using the stored values of Sum and Count that has been calculated up to the penultimate word of that sentence, as

C = Sum of letter count up to penultimate word in a given sentence   / Count of words up to the penultimate word in the sentence. 

The Sum and Count value are reset to 0 at the end of each sentence so that for the next sentence, a new value of Sum and Count gets calculated by the procedure Sum, Count, and thereafter the value of C is calculated and compared with B to get the value of A, inside the IF loop.

 For the 1st sentence:  C =  11/ 3 = 3.66

For the 2nd sentence: C =  32/6 =  5.33

For the 3rd sentence:  C =  42/7 =  6

For the 4th sentence:  C = 88/20 = 4.4

For the 5th sentence:  C = 123/24 = 5.125


PROCEDURE DoSomething (C, B, A)

Compares the values of C with B and return the value of A variable as A+1 if C < B is true, or else return the value of A variable as A itself.

For the 1st sentence:  C = 3.66, B = 5.077 , so C < B is True. So, enter the If loop and return the value of A= A+1= 0+1 = 1 (A value gets updated to 1 from the initial value 0 at the end of 1st sentence)

For the 2nd sentence: C = 5.33, B = 5.077, so C < B is false. So, enter the else loop and return the value that’s currently stored in A which is 1.

For the 3rd sentence:  C = 6, B = 5.077, so C < B is false. So, enter the else loop and return the value that’s currently stored in A which is 1.

For the 4th sentence:  C = 4.4,  B = 5.077, so C < B is True. So, enter the If loop and return the value of A = A+1= (current value stored in A variable)+1, which is 1+1 = (A value gets updated a second time to 2 from it's previous stored value 1 at the end of the 4th sentence)

For the 5th sentence:  C = 5.125, B = 5.077, so C < B is false. So, enter the else loop and return the value that’s currently stored in A which is 2.

Reply all
Reply to author
Forward
0 new messages