#leo def endswith_case_insensitive(s, suffix): """s and suffix are stings returns True if s ends with suffix, case insensitive""" return s.lower().endswith(suffix.lower()) #sharma++ def endswith_case_insensitive(s, suffix): suffix = suffix.lower() s = s[len(s)-len(suffix):len(s)] #print(s) #print(suffix) return s == suffix # boolean ipsa loquitor. POLLARD def occurs_twice(s, ch): """s is a string, ch is a one-character string return True if ch occurs at least twice in s.""" if s.count(ch) > 1: return True else: return False #Pollard++; def occurs_twice(s, ch): """s is a string, ch is a one-character string return True if ch occurs at least twice in s.""" return s.count(ch) > 1 def occurs_twice(s, ch): first = s.find(ch) last = s.rfind(ch) return not(first==last) # return first != last # return first < last def median(x): """ x is a numerical list with an odd number of items returns the median of x""" #pittenger x = sorted(x) return x[len(x)//2] def median(x): """ x is a numerical list with an odd number of items returns the median of x""" #pittenger x.sort() return x[len(x)//2] #vester def format_name(first, last, middle): """ first, last are strings (name) return a sring for the form "last, first (middle initial).""" return last + ", " + first + " " + middle[0] + "." #paul warner def format_name(first, last, middle): return f"{last}, {first} {middle[0]}." def format_name(first, last, middle): return "{0}, {1} {2}.".format(last, first, middle[0]) def format_name(first, last, middle): return "%s, %s %s." % (last, first, middle[0]) print(endswith_case_insensitive("flibbertygibbet", "BeT")) print(format_name("John", "Morrison", "Michael")) x = [5,3,9,-2,7] print(x) print(median(x)) print(x)