Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle RMAN For Absolute Beginners

Authors: Darl Kuhn

1st Edition

1484207637, 9781484207635

More Books

Students also viewed these Databases questions