How to count the #of of items in a list without using python's method while ignoring the items that come after a certain item -
this our review homework test. have absolutely no idea how have been away quite while. if tell me need learn able complete task. program output how many places need visit before la dodgers stadium on way. places visited after la dodgers stadium don't count. must output number of places visited have have names more 1 word (ex. san jose.) catch must use while loop in case - may not use python's find method.
sample
>>> places= ["home","in-n out burger", "john's house", "santa monica pier", "staples center", "la dodgers stadium", "home" ] >>> placescount(places) 6 places la dodgers stadium 5 multi-word names
here's did:
places= ["home","in-n out burger", "john's house", "santa monica pier", "staples center", "la dodgers stadium", "home" ] def placescount(places): placestogo = 0 in range (len(places)): if places[i] == "la dodgers stadium": placestogo = placestogo + 1 print placestogo, "places la dodgers stadium" else: placestogo = placestogo + 1 def multicount(places): spaces = 0 multiwords = 0 j in range (len(places)): word = places[j] characters in word: if characters == " ": spaces = spaces + 1 if spaces != 0: multiwords = multiwords + 1 spaces = 0 print multiwords, "multi-word names" placescount(places) multicount(places)
Comments
Post a Comment