Question: 3 . The following code is supposed to take one letter as input, and count and print how many times that letter appears in each

3. The following code is supposed to take one letter as input, and count and print how many times
that letter appears in each string stored in a 2-D grid. However, there is a semantic error in
this code that causes it to print incorrect values in some cases.
1 grid =[["zxy","abc" , "lmnop" ],
2["an apple a day" , "keeps doctors away" ,"at least, as they say" ],
3["lalala", "loolooloo" , "doopdedoop" ]]
4
5 search = input("Please type one letter>")
6 for row in range(len(grid)):
7 c =0
8 for col in range(len(grid[row])):
9 for letter in grid[row][col]:
10 if letter == search:
11 c +=1
12 print(c, end="")
13
(a) Write a specific input that is not affected by the error, and the corresponding correct
output produced by the program.
Input:
Output:
(b) Write a specific input that does trigger the error, and the corresponding incorrect output
produced by the program. This input should still be correctly-formatted: a single letter
string.
Input:
Output:
(c) What is the error, and how can it be fixed?
3

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!