# Debugging example - fix this! # def is_reverse(word1, word2): if len(word1) != len(word2): return False i = 0 j = len(word2) while j > 0: # Use print line below to help debug ... #print("i = ", i, "j = ", j) if word1[i] != word2[j]: return False i = i + 1 j = j - 1 return True # for loops and range # # how do we do the equivalent of loopChars (from lec8loopchars.py) # with a for loop and range. loopChars2 doesn't give us access to the # index. # def loopCharsWithIndex(inputString): for currentIndex in range(len(inputString)): currentChar = inputString[currentIndex] print(currentChar, currentIndex) return ########## # # Questions like some that might be on quiz 1 def ex1a(n1, n2): return (not (n1 > 5)) or (n2 <= 10) # Give simple expresssions for a, b, c, d, e so that ex1a and ex1b are equivalent. # Your answers MUST NOT include any AND, OR, or NOT operations. They must # be simple comparisions between numbers and/or variables, or return statements. def ex1b(n1, n2): # if ---a--- # ---b--- # if ---c--- # ---d--- # ---e--- if n2 <= 10: return True if n1 <= 5: return True return False # Do f1a and f1b return the same thing for every possible input string? # If not, provide example input for which they return diffrent results. # def f1a(string1): i = 0 newString = "" while i < len(string1): newString = newString + string1[i] + string1[i] i = i + 2 return newString def f1b(string1): i = len(string1) - 1 newString = "" while i >= 0: newString = string1[i] + string1[i] + newString i = i - 2 return newString