Question: PROGRAMMING II EXERCISES - 1 TO 6 - CAN BE DONE IN ONE PYTHON FILE (6PTS EACH) This chapter showed us how to sum a

PROGRAMMING II EXERCISES - 1 TO 6 - CAN BE DONE IN ONE PYTHON FILE (6PTS EACH) This chapter showed us how to sum a list of items, and how to count items. The counting example also had an if statement that let us only count some selected items. In the previous chapter we also showed a function find_first_2_letter_word that allowed us an early exit from inside a loop by using return when some condition occurred. We now also have break to exit a loop (but not the enclosing function, and continue to abandon the current iteration of the loop without ending the loop. Composition of list traversal, summing, counting, testing conditions and early exit is a rich collection of building blocks that can be combined in powerful ways to create many functions that are all slightly different. Answers to questions from 1-6

PROGRAMMING II EXERCISES - 1 TO 6 - CAN BE DONE IN

The first six questions are typical functions you should be able to write using only these building blocks . Write a function to count how many odd numbers are in a list. 2. Sum up all the even numbers in a list. a Sum up all the negative numbers in a list. 4. Count how many words in a list have length 5 s. Sum all the elements in a list up to but not including the first even number. (Write your unit tests What if there is no even number?) 6. Count how many words occur in a list up to and including the first occurrence of the word "sam" (Write your unit tests for this case too. What if "sam" does not occur?)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!