Question: Write function where user is asked to make an entry, and the square of the entry is printed. Use a while loop with a try,
Write function where user is asked to make an entry, and the square of the entry is printed. Use a while loop with a try, except, else block to account for incorrect inputs.
User will call the function once, and function will request an entry. If the entry is, valid then the function will print out the square of the entry. If not valid, then user will be prompted to the error, and asked to enter a new value.
For this exercise, a solution includes using break and continue statements as well as try,except, else block with while. You may have a different version, importance is on whether when called can your function execute as described.
Question 6: Create function that uses filter to return words from a list of words that starts with a given letter.
The function will have an input of a string, and output a list of integers. example:
find_words(['lettuce','beans','apple','cat','dog','boy','girl','chicago','type'],'b') ['beans', 'boy']Hint: you can use a lambda function to use with filter!
I keep getting an error when I write the function out:
In [143] # add your code here def find_words (words, letter): return list(filter (lambda x: x[0] == letter, words)) In [144]: print (find_words (['lettuce', 'beans', 'apple', 'cat', 'dog', 'boy', 'girl', 'chicago', 'type'], 'b')) TypeError Traceback (most recent call last) Input In [144], in () ----> 1 print (find_words (['lettuce', 'beans', 'apple", 'cat', 'dog', 'boy','girl', 'chicago', 'type'], 'b')) Input In [143], in find_words (words, letter) 2 def find words (words, letter): ---> 3 return list(filter(lambda x: x[0] == letter, words)) TypeError: 'list' object is not callable
Step by Step Solution
3.47 Rating (150 Votes )
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
