Computational Thinking
Graded Assignment Week 1
Computational Thinking
   Graded Assignment Week 1
   Question
       Statement
       Question 1 [2 marks]
       Answer
       Question 2 [2 marks]
       Answer
       Question 3 [2 marks]
       Answer
       Solution
   Question 4 [4 marks]
       Statement
       Options
           (a)
           (b)
           (c)
           (d)
       Answer
       Solution
   Question 5 [5 Marks]
       Statement
       Options
           (a)
           (b)
           (c)
           (d)
           (e)
       Answer
       Solution
   Question 6 [5 Marks]
       Statement
       Options
           (a)
           (b)
           (c)
           (d)
       Answer
       Solution
   Question 7 [5 Marks]
       Statement
       Question
       Options
           (a)
           (b)
            (c)
            (d)
        Answer
            Solution
    Question 8 [3 Marks]
        Statement
        Options
            (a)
            (b)
            (c)
            (d)
        Answer
        Solution
    Question 9 [3 Marks]
        Statement
        Options
            (a)
            (b)
            (c)
            (d)
        Answer
        Solution
    Question 10 [3 Marks]
        Statement
        Options
            (a)
            (b)
            (c)
            (d)
            (e)
        Answer
        Solution
Question
Statement
What will be the values of A, B and C after execution of the following procedure using the "Scores" dataset?
Step 1: Arrange all cards in a single pile called Pile 1
Step 2: Maintain three variables A, B, C and initialize them to 0
Step 3: If Pile 1 is empty then stop the iteration
Step 4: Read the top card in Pile 1
Step 5: If Mathematics < 50 then increment A
Step 6: If Physics < 50 then increment B
Step 7: If Chemistry < 50 then increment C
Step 8: Move the current card to another pile called Pile 2 and repeat from step 3
Question 1 [2 marks]
The value of A is _ _ _ _ ?
Answer
2
Question 2 [2 marks]
The value of B is _ _ _ _ ?
Answer
1
Question 3 [2 marks]
The value of C is _ _ _ _ ?
Answer
1
Solution
In this question we have to find exact values of three variables A, B and C. So, let us start with the
procedure. Here in step 2 we have declared three variables A, B, C and also initialized them to 0. In step 5,
variable A is getting incremented if Mathematics marks of a student is less than 50 which means we are
counting the number of students who have secured less than 50 marks in Mathematics. In step 6, variable B
is getting incremented if Physics marks of a student is less than 50 which means we are counting the
number of students who have secured less than 50 marks in Physics. In step 7 we are checking for the
students whose Chemistry marks are less than 50 which means variable C is counting the number of
students who secured less than 50 marks in Chemistry. It is a repeat step which indicates that this
procedure is getting executed on all the cards available in the dataset. Therefore, if we compile all the
Mathematics, Physics and Chemistry marks from the dataset then we will get following categorization:
    Cards counted under variable                                           Card numbers
    A                                                                      3,24
    B                                                                      1
    C                                                                      16
Question 4 [4 marks]
Question 4 [4 marks]
Statement
What will variable B represent after execution of the following procedure on the "Words" dataset?
Step 1: Arrange all cards in a single pile called Pile 1
Step 2: Maintain two variables A, B and initialize them to 0
Step 3: If Pile 1 is empty then stop the iteration
Step 4: Read the top card in Pile 1
Step 5: If PartOfSpeech is "Verb" then increment A
Step 6: If the word does not end with a full stop then execute Step 9
Step 7: If the word ends with a full stop and A is greater than 1 then increment B
Step 8: Reset the variable A to 0
Step 9: Move the current card to another pile called Pile 2 and repeat from Step 3
Options
(a)
Total number of verbs in the dataset
(b)
Total number of sentences with only one verb in it
(c)
Total number of sentences with at least two verbs in it
(d)
Total number of sentences with at least one verbs in it
Answer
(c)
Solution
Let us analyze the given procedure, in Step 2 two variables A and B are initialized to 0. In Step 5 variable A is
getting incremented if PartOfSpeech is "Verb" which means variable A is counting number of Verbs.
Conditions in Steps 6 and 7 are exactly opposite to each other. As per the combination of Steps 6 and 9 we
are counting nouns with variable A until we reach to a full stop. In other words, we are counting number of
Verbs in each sentence. As per Step 7 if a sentence ends and Verb count in variable A is greater than 1 then
we are incrementing variable B. Step 8 resets the value of variable A so that the same variable can be used
to count number of Verbs in the next sentence. Based on this analysis we can conclude that the variable B
gets incremented only if variable A’s value is greater than 1 which means if A is 2 or more. Hence, the
answer of this question is Total number of sentences with at least two verbs in it.
Question 5 [5 Marks]
Question 5 [5 Marks]
Statement
A student proposed a hypothesis that less number of students are born in the first half of the year than the
second half of the year. She wrote the following procedure which uses the “Scores” dataset to verify the
hypothesis. However, the procedure may contain some errors. Find out the errors if present.
Step 1: Arrange all cards in a single pile called Pile 1
Step 2: Maintain two variables A and B and initialize them to 0
Step 3: If Pile 1 is empty then stop the iteration and start from Step 8
Step 4: Read the top card in Pile 1
Step 5: If the Date of Birth is from 1st January to 30th June then increment A
Step 6: If the Date of Birth is from 1st July to 31st December then increment B
Step 7: Move the current card to another pile called Pile 2 and repeat from Step 3
Step 8: If A > B then declare the hypothesis to be True
Step 9: If A ≤ B then declare the hypothesis to be False
Options
(a)
Step 5 to increment A is incorrect
(b)
Step 6 to increment B is incorrect
(c)
Step 8 to declare the hypothesis as True is incorrect
(d)
Step 9 to declare the hypothesis as False is incorrect
(e)
The procedure is free of errors
Answer
(c), (d)
Solution
In Step 1 cards are arranged into a single pile and which is called as Pile 1. In Step 2 we are creating two
variables called A and B then assigning the value 0 to them. Step 3 checks whether the iteration has to be
continued or not. If the pile 1 is empty then the iteration has to be stopped. In Step 4, the top card of the
Pile 1 is taken and read. Now, one has to count the number of people who are born in the first half of the
year and who are born in the second half of the year. In Step 5, we increment A if a student is born from 1st
January to 30th June. In Step 6, we increment B if a student is born from 1st July to 31st December. In Step 7,
the current card is moved to another called Pile 2 and the procedures are repeated from Step 3. After
reading all cards, variables A and B will store the number of students whose Date Of Birth are in the first and
the second half of the year respectively. So to verify the hypothesis, the values of A and B should be
compared with each other. If the value of A is less than B it will confirm the hypothesis to be True and if the
value of A is greater than or equal to B it will confirm the hypothesis to be False. Hence, Step 8 and 9 are
incorrect. The correct answers are (c) and (d).
Question 6 [5 Marks]
Statement
What will variable X represent after execution of the following procedure on the "Shopping Bills" dataset?
Step 1: Arrange all cards in a single pile called Pile 1
Step 2: Maintain four variables A, B, C, X and initialize them to 0
Step 3: If Pile 1 is empty then stop the iteration and start from Step 9
Step 4: Read the top card in Pile 1
Step 5: If the Shop name is "SV Stores" and Customer name is "Suresh" then set A equal to 1
Step 6: If the Shop name is "Big Bazaar" and Customer name is "Suresh" then set B equal to 1
Step 7: If the Shop name is "Sun General" and Customer name is "Suresh" then set C equal to 1
Step 8: Move the current card to another pile called Pile 2 and repeat from Step 3
Step 9: Update the value of X as X = A + B + C
Options
(a)
Number of distinct stores Suresh has visited
(b)
Number of distinct stores Suresh never visited
(c)
Numbers of times Suresh has visited Sun General
(d)
Numbers of bills in the dataset belong to Suresh
Answer
(a)
Solution
Variables A, B, C, and X are initialized to 0 in Step 2. In Step 5 variable A's value will be set to 1 if "Suresh"
has a shopping bill from "SV stores". Similarly, in Step 6 variable B's value will be set to 1 if he has a bill from
"Big Bazaar" and variable C's value for "Sun General" in Step 7. In Step 9 value of X is updated to with sum
of A, B and C. Values of variables A, B and C either 1 or 0 based on the information if "Suresh" has visited
the corresponding shop or not. Therefore, X will store the number of distinct shops visited by Suresh.
Question 7 [5 Marks]
Statement
The following procedure is executed using the “Olympics” dataset.
Step 1: Arrange all cards in a single pile called Pile 1
Step 2: Maintain a variable X and initialize it to True
Step 3: If Pile 1 is empty then stop the iteration
Step 4: Read the top card in Pile 1
Step 5: If the Gender is "F" and Nationality is "Korean" then set X equal to False
Step 6: Move the current card to another pile called Pile 2 and repeat from step 3
Question
At the end of the execution, X will be True if
Options
(a)
there exist at least one female player who is not from Korea
(b)
there exist at least one female player who is from Korea
(c)
all the female players are from countries other than Korea
(d)
all the female players are from Korea only
Answer
(c)
Solution
In Step 1, cards are arranged into a single pile and which is called as Pile 1. In Step 2 we are creating a
variable called X and initializing it to True. Step 3 checks whether the iteration has to be continued or not. If
the Pile 1 is empty then the iteration has to be stopped. In step 4, we read the first card in Pile 1. In step 5
we check if the card representing a player information has Gender equal to "F" and Nationality equal to
"Korean", the X is set to False. This means X remains true only if there is no card in the Pile 1 corresponding
to Gender equal to "F" and Nationality equal to "Korean". In step 6, we move the current card from Pile 1 to a
new Pile called Pile 2, and repeatedly move to the other cards of the Pile. Therefore, X is true only when
Gender is not equal to "F" and Nationality is not equal to "Korean". This means X is true means all the female
players are from countries other than Korea.
Question 8 [3 Marks]
Question 8 [3 Marks]
Statement
The following procedure is executed using the "Library" dataset. At the end of the execution, count stores
the number of books written by "Shakespeare" and published in "Morning Star" publications. But the
programmer may have made mistakes in one or more steps. Identify all such steps (if any). It is a Multiple
Select Question (MSQ).
Step 1: Arrange all cards in a single pile called Pile 1
Step 2: Maintain a variable count and initialize it to 1
Step 3: If Pile 1 is empty then stop the iteration
Step 4: Read the top card in Pile 1
Step 5: If Author == "Shakespeare" or Publisher == "Morning Star" then increment count
Step 6: Move the current card to another pile called Pile 2 and repeat from step 3
Options
(a)
Step 2: Incorrect initialization of the variable count
(b)
Step 3: Incorrect step for stopping the iteration
(c)
Step 5: Incorrect condition to update count
(d)
Step 6: Incorrect step indicated from where the procedure has to be repeated
Answer
(a), (c)
Solution
count is supposed to store the number of books written by "Shakespeare" and published in "Morning Star"
publications. It cannot be initialized with one as this initialization counts one book extra. Hence step 2 is
incorrect. In step 5, the and constraint is missing. As a result, the books that are written by "Shakespeare"
and published in another publications may also be counted. Similarly, a book published in "Morning Star"
publications but written by another author may also be counted in addition to the books written by
"Shakespeare" and published in "Morning Star" publications. Therefore, step 5 is also incorrect.
Question 9 [3 Marks]
Question 9 [3 Marks]
Statement
Match the following by selecting the most appropriate datatype.
      Field name                                                      Datatype
      1. Names of students in the "Scores" dataset                    i. Integer
      2. Gender of players in the "Olympics" dataset                  ii. Boolean
      3. Page count of books in the "Library"                         iii. String
      4. City of a student in the "Scores" dataset                    iv. Character
      5. Year in the "Library" dataset                                v. Float
Options
(a)
1: iii, 2: iv, 3: i, 4: iv, 5: v
(b)
1: iii, 2: ii, 3: i, 4: iii, 5: v
(c)
1: iii, 2: iv, 3: i, 4: iii, 5: i
(d)
1: iv, 2: ii, 3: i, 4: iv, 5: i
Answer
(c)
Solution
      1. Names of students in the "Scores" dataset is string.
      2. Gender of players in the "Olympics" dataset is a character
      3. Page count of books in the "Library" is an Integer
      4. City of a student in the "Scores" dataset is string
      5. Year in the "Library" dataset is integer
Question 10 [3 Marks]
Question 10 [3 Marks]
Statement
The following procedure is executed using the "Olympics" dataset. At the end of the execution, count stores
the number of Indian players who have won a "Gold" medal. But the programmer has missed few Steps.
Identify all correct Steps.
Step 1: Arrange all cards in a single pile called Pile 1
Step 2: Maintain a variable count and initialize it to 0
Step 3: ______________________________________
Step 4: Read the top card in Pile 1
Step 5: _______________________________________
Step 6: Move the current card to another pile called Pile 2 and repeat from Step 3
Options
(a)
Step 3: If Pile 1 is empty move to Pile 2
Step 5: If HostCountry == "Indian" or Medal == "Gold" then increment count
(b)
Step 3: If Pile 1 is empty then stop the iteration
Step 5: If Nationality == "Indian" or Medal == "Gold" then increment count
(c)
Step 3: If Pile 1 is empty move to Pile 2
Step 5: If Nationality == "Indian" or Medal == "Gold" then increment count
(d)
Step 3: If Pile 1 is empty then stop the iteration
Step 5: If Nationality == "Indian" and Medal == "Gold" then increment count
(e)
Step 3: If Pile 1 is empty then stop the iteration
Step 5: If HostCountry == "Indian" and Medal == "Gold" then increment count
Answer
(d)
Solution
In Step 1 cards are arranged into a single pile and which is called as Pile 1. In Step 2 we are creating a
variable called count and initializing it to 0. Step 3 must check whether the iteration has to be continued or
not. If the Pile 1 is empty then the iteration has to be stopped. In step 4, we read the first card in Pile 1.
count is supposed to store the number of players whose Nationality is Indian and Medal is "Gold". In Step 5,
the condition must be evaluated and count should be incremented. Hence, the correct option is (d).