# 11. My code ouput is wrong but i still passed asssignment HOW?

#1

My program works with integers but doesnt work with strings
I still passed the assignment HOW???
Anyways, plz help me with the mistake i am making
i understand that i am trying to handle strings with a logic of intgers but still,
in that case then it shouldnt work allt ogether.

I want to be able to count the strings too, right now it counts only zero
here is my code below.

sequence="the the the the kostkc sdjnvithe therrrw theis"
item="the"
def count(sequence,item):
reps=0
#    sequence=sequence.split()
for x in range(len(sequence)):
if sequence[x]==item:
reps+=1
#    seq=' '.join(sequence)
return reps
print count(sequence,item)
print count("the the the the kostkc sdjnvithe therrrw theis","the")

#2

it would work if the sequence:

"the the the the kostkc sdjnvithe therrrw theis"

was a list, then it would loop over the separate words. Because its a string, it will loop over each individual character, one letter will never equal a word

#3

in that case, i still am wondering
HOW DID I PASS the assignment?

it has to work for all right??
almost like a whole and sole-ish solution, right.

i tried making it a list and it still didnt work
i TRIED SPLIT and JOIN LIKE in previous assignment of CENSOR,
then it WORKED just fine and counted all the duplicates
BUT I DIDNT PASS ASSIGNMENT by doing that
(look this code, in that look at comment lines, i tried that kind of code which works but doesnt pass)

sequence="the the the the kostkc sdjnvithe therrrw theis"
item="the"
def count(sequence,item):
reps=0
#    sequence=sequence.split()
for x in range(len(sequence)):
if sequence[x]==item:
reps+=1
#    seq=' '.join(sequence)
return reps
print count(sequence,item)
print count("the the the the kostkc sdjnvithe therrrw theis","the")

#4

But the argument at function call should be a list, this function was never suppose to work for string arguments.

here:

print count("the the the the kostkc sdjnvithe therrrw theis","the")

the first argument should be a list.

#5

AAAHHHHH yes ok now i understand completely.
The assignment purpose was different and purview was diff.....yes ok..
I kind of was not reading well in this case and as soon as i read the question i started imagining strings and list and the whole concert..

thnx

#6