def num_vowels(s): '''Return the number of vowels in string s. The letter "y" is not treated as a vowel.''' count = 0 for char in s: if char in "aAeEiIoOuU": count = count + 1 return count def remove_spaces(s): '''Return s with any spaces removed.''' s_no_spaces = "" for char in s: if char != " ": s_no_spaces += char return s_no_spaces def count_matches(s1, s2): '''Return the number of chars in s1 that appear in s2.''' common_chars = 0 for char in s1: if char in s2: common_chars += 1 return common_chars def grade(myAns,correctAnswer): if myAns == correctAnswer: print("Correct, the answer is",myAns) else: print("My answer is",myAns,"but the correct answer is",correctAnswer) def main(): #test them out grade(num_vowels('hello there fellow'), 6) grade(num_vowels('jjjddjsjsjd jjjj'), 0) grade(num_vowels(''),0) grade(num_vowels('a'),1) grade(num_vowels('b'),0) #test them out grade(remove_spaces('hello there fellow'),'hellotherefellow') grade(remove_spaces('jskrjeksuuyj'),'jskrjeksuuyj') grade(remove_spaces(''),'') grade(remove_spaces(' '),'') grade(remove_spaces(' b'),'b') grade(count_matches("abcde","cdefg"), 3) grade(count_matches("abcde","fghij"), 0) grade(count_matches("abcde",''), 0) grade(count_matches('',''), 0) grade(count_matches('','abcde'), 0) #now, let's write some code to reverse a list. We won't create a function. #just to see that this is possible. s = 'abc' reverse = "" # An accumulator for char in s: reverse = char + reverse grade(reverse, 'cba') main()