5. Sum all the elements in a list up to but not including the first even number.(Write vour unit tests. What if there is no even number?)

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
Need help with question# 5 and 9 using python programming and if you take a screenshot that will help to follow
s In a list u to but not including the first even nurmber. (Write your
Anit 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?)
7 Add a print function to Newton's sqrt function that prints out better each time it is
calculated. Call your modified function with 25 as an argument and record the results.
8. Trace the execution of the last version of print_mult table and figure out how it
works.
9 Write a lunction print triangular numbers (n) that prints out the first n tri-
angular numbers. A call to print_triangular_numbers (5) would produce the
following output:
7.26. Exercises
109
Type here to search
Transcribed Image Text:s In a list u to but not including the first even nurmber. (Write your Anit 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?) 7 Add a print function to Newton's sqrt function that prints out better each time it is calculated. Call your modified function with 25 as an argument and record the results. 8. Trace the execution of the last version of print_mult table and figure out how it works. 9 Write a lunction print triangular numbers (n) that prints out the first n tri- angular numbers. A call to print_triangular_numbers (5) would produce the following output: 7.26. Exercises 109 Type here to search
7.26 Exercises
This chapter showed us how to sum a list of items, and how to count items. The counting exam-
ple 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.
Adc
Con
or E
Set
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.
The first six questions are typical functions you should be able to write using only these building
blocks.
1. Write a function to count how many odd numbers are in a list.
2. Sum up all the even numbers in a list.
3. Sum up all the negative numbers in a list.
4. Count how many words in a list have length 5
5. Sum all the elemenis in a list up to but not including the first even number. (Wnte vour
unit tests. What if there is no even number?)
6 Count how many words
eor the word
区
Transcribed Image Text:7.26 Exercises This chapter showed us how to sum a list of items, and how to count items. The counting exam- ple 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. Adc Con or E Set 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. The first six questions are typical functions you should be able to write using only these building blocks. 1. Write a function to count how many odd numbers are in a list. 2. Sum up all the even numbers in a list. 3. Sum up all the negative numbers in a list. 4. Count how many words in a list have length 5 5. Sum all the elemenis in a list up to but not including the first even number. (Wnte vour unit tests. What if there is no even number?) 6 Count how many words eor the word 区
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Knowledge Booster
Module hierarchy chart
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education