I am trying to make a function that takes in a list as an input parameter. I am to use a while loop to iterate over the list and keep track of the amount of integers and strings that are included in the list. This is what i have so far:
def usingwhileloop(mylist):
count = 0
int_total = 0
str_total = 0
while count <= len(mylist):
if isinstance(mylist[count], int) == True:
int_total = int_total + 1
elif isinstance((mylist[count]), str) == True:
str_total = str_total + 1
count = count + 1
newlist = [int_total, str_total]
return newlist
When I run for a list like [1, 2, 3, “a”, “b”, 4] it should return [4, 2] but instead i get the following error: "line 51, in usingwhileloop if isinstance(what[count], int) == True: IndexError: list index out of range"
what am i doing wrong? I struggle with while loops...