''' Purpose: consider string casing functions ''' text = input( "Enter text: " ) text = text.lower() # Reassigns text to be the lowercase version of the original value of text substring = input( "Enter substring: " ) substring = substring.lower() # Reassigns substring to be the lowercase version of the original value of substring i = input( "Enter index: " ) i = int( i ) print() # count occurrences of text # NEW FUNCTION: count() -> s.count( substring we want to count ) -> gives you the number of times the # substring occurs in the string (counts the thing in parentheses in the string s) total = text.count( substring ) from_index_i_on = text.count( substring, i ) # You can also provide an optional index i # that basically says that it will look for the substring starting from index i (including index i) #1 #2 #3 where 'an' occurs # 'any bananas' # 012345678910 # In the entire string, there are three occurences of 'an' # From 7 onwards (including index 7), there is only 1 'an' # The substring is case-sensitive! # 'Any bananas' # ^ This 'An' is not 'an' so it doesn't count (not part of the count) # How can we still find the right count even if it's different cases? # Make everything lowercase (all characters lowercase) # Count lowercase version of substring we want print( "text.count( substring ) =", total, " # count all" ) print( "text.count( substring,", i, ") =", from_index_i_on, " # count starting from index", i )