pythonedx

Why does my code throw up an extremely odd error code?


I am doing Georgia Tech's CS1301xII lately. However, this question's error message is just strange

mystery_list = ["Taylor Swift", "Twenty Two", "Georgia Tech"]

#You may modify the lines of code above, but don't move them!
#When you Submit your code, we'll change these lines to
#assign different values to the variables.

#Above is a list of strings. Don't worry if this syntax is a
#little unfamiliar, we'll talk you through it and then cover
#it more in chapter 4.3.
#
#Write some code that will count the number of instances of
#the letter 't' in the list of strings. Count both capital
#'T' and lower-case 't'. Then, print the number of instances
#of the letter 't'.
#
#For example, with the list declared above, you would print
#6: two in the first string, three in the second, one in the
#third.
#
#Because we haven't used lists very extensively, we've
#gotten you started. The loop below will iterate through each
#string in the list. Next, you want to iterate through each
#letter in the current string, check if it's a t, and
#increment a counter if so.


#You'll want to add some code before the loop here.
counter = 0
listnum = 0
listletter = 0
for string in mystery_list:
   while listnum <= len(mystery_list):
       if mystery_list[listnum][listletter] == "T" or mystery_list[listnum][listletter] == "t":
           listletter += 1
       if listletter > len(mystery_list[listnum]):
           listletter = 0
           listnum += 1

This is the error message:

../resource/scripts/run.sh: line 1: 669 Killed python3 $VOC_SELECTED_FILE Command exited with non-zero status 137

If it were a usual error like syntax or division by zero or pretty much every single error, it would give me the non-zero status 1. So my questions are: 1. How do I fix my code 2. What does this error message even mean???


Solution

  • You have an infinite loop in your code. listnum is always 0 causing Infinite while loop. So the server is terminating your script giving the weird error.

    Here is a simple solution:

    mystery_list = ["Taylor Swift", "Twenty Two", "Georgia Tech"]
    counter = 0
    for string in mystery_list:
        counter+=string.lower().count("t")