Write a function called getLetter() that asks the user for a letter and returns the given letter. Your function should check to make sure the user enters just a single letter. If the user enters anything other than a single letter, the function should ask again, until it receives valid input.
Write a function called avgList that, given a list of numbers, calculates and returns their average. For example, avgList([5, 10, 5, 4]) should return 6. Write a main program to test the function.
Write a function called maxList that, given a list of numbers, finds and returns the largest number in the list. For example, maxList([7,4,8,1]) should return 8. Write a main program to test the function.
Consider the following program.
def main(): print("in main") test = "whee" check = "e" answer = helper(test, check) print("the answer is %d" % (answer)) def helper(word, letter): print("in helper") print("word: %s" % (word)) print("letter: %s" % (letter)) x = 0 for ch in word: if ch == letter: x = x+1 # draw stack here, just before return return x main()
Question 4 Answer Key
def update(L, S): count = 0 data = S.split() for item in data: if item not in L: L.append(item) count = count + 1 # draw stack here return count def main(): words = ['roses','are','red'] print(words) line = 'violets are blue' result = update(words,line) print(result) print(words) main()
Question 5 Answer Key
Thanks Goodness It's Friday
Your program will create and print out the string "TGIF"