Problem Solving with C++ plus MyProgrammingLab with Pearson eText-- Access Card Package (9th Edition)
9th Edition
ISBN: 9780133862218
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 3.4, Problem 37STE
Write a loop that will read in a list of even numbers (such as 2, 24, 8, 6) and compute the total of the numbers on the list. The list is ended with a sentinel value. Among other things, you must decide what would be a good sentinel value to use.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
The for loop iterates across the elements in a given list. So long as there are objects to process, it will keep going. In what way does this statement hold true or false?
Can I have some help making a program that has the user append 5 names into a list using a loop? The names need to be in the format LastName-FirstName, with the – separating first/last. Then, using a second loop, split each name based on -.
This problem has you write a nested loop to process a list of list of int, and accumulate a list of list of int. The starter code provides an accumulator for the result and a loop over the lists, and you need to write the code that checks whether sublist contains only even ints.You'll probably want a one-way flag: a Boolean variable that starts out as True and is set to False if you find an odd int in the sublist. You'll need to check the value of this variable to figure out whether to append sublist to the even_lists accumulator.
from typing import List
def only_evens(lst: List[List[int]]) -> List[List[int]]: """Return a list of the lists in lst that contain only even integers. >>> only_evens([[1, 2, 4], [4, 0, 6], [22, 4, 3], [2]]) [[4, 0, 6], [2]] """ even_lists = []
for sublist in lst: # write your code here (please read above for a suggested approach)
return even_lists
Chapter 3 Solutions
Problem Solving with C++ plus MyProgrammingLab with Pearson eText-- Access Card Package (9th Edition)
Ch. 3.1 - Determine the value, true or false, of each of the...Ch. 3.1 - Name two kinds of statements in C++ that alter the...Ch. 3.1 - In college algebra we see numeric intervals given...Ch. 3.1 - Prob. 4STECh. 3.2 - What output will be produced by the following...Ch. 3.2 - What output will be produced by the following...Ch. 3.2 - What would be the output in Self-Test Exercise 6...Ch. 3.2 - What would be the output in Self-Test Exercise 6...Ch. 3.2 - What output will be produced by the following...Ch. 3.2 - What would be the output in Self-Test Exercise 9...
Ch. 3.2 - What output will be produced by the following...Ch. 3.2 - Write a multiway if-else statement that classifies...Ch. 3.2 - Given the following declaration and output...Ch. 3.2 - Given the following declaration and output...Ch. 3.2 - What output will be produced by the following...Ch. 3.2 - What would be the output in Self-Test Exercise 15...Ch. 3.2 - What would be the output in Self-Test Exercise 15...Ch. 3.2 - What would be the output in Self-Test Exercise 15...Ch. 3.2 - Prob. 19STECh. 3.2 - Though we urge you not to program using this...Ch. 3.3 - Prob. 21STECh. 3.3 - Prob. 22STECh. 3.3 - What is the output of the following (when embedded...Ch. 3.3 - What is the output of the following (when embedded...Ch. 3.3 - Prob. 25STECh. 3.3 - What is the output of the following (when embedded...Ch. 3.3 - Prob. 27STECh. 3.3 - For each of the following situations, tell which...Ch. 3.3 - Rewrite the following loops as for loops. a.int i...Ch. 3.3 - What is the output of this loop? Identify the...Ch. 3.3 - What is the output of this loop? Comment on the...Ch. 3.3 - What is the output of this loop? Comment on the...Ch. 3.3 - What is the output of the following (when embedded...Ch. 3.3 - What is the output of the following (when embedded...Ch. 3.3 - What does a break statement do? Where is it legal...Ch. 3.4 - Write a loop that will write the word Hello to the...Ch. 3.4 - Write a loop that will read in a list of even...Ch. 3.4 - Prob. 38STECh. 3.4 - Prob. 39STECh. 3.4 - What is an off-by-one loop error?Ch. 3.4 - You have a fence that is to be 100 meters long....Ch. 3 - Write a program to score the paper-rock-scissor...Ch. 3 - Write a program to compute the interest due, total...Ch. 3 - Write an astrology program. The user types in a...Ch. 3 - Horoscope Signs of the same Element are most...Ch. 3 - Write a program that finds and prints all of the...Ch. 3 - Buoyancy is the ability of an object to float....Ch. 3 - Write a program that finds the temperature that is...Ch. 3 - Write a program that computes the cost of a...Ch. 3 - (This Project requires that you know some basic...Ch. 3 - Write a program that accepts a year written as a...Ch. 3 - Write a program that scores a blackjack hand. In...Ch. 3 - Interest on a loan is paid on a declining balance,...Ch. 3 - The Fibonacci numbers F are defined as follows. F...Ch. 3 - The value ex can be approximated by the sum 1 + x...Ch. 3 - Prob. 8PPCh. 3 - Prob. 9PPCh. 3 - Repeat Programming Project 13 from Chapter 2 but...Ch. 3 - The keypad on your oven is used to enter the...Ch. 3 - The game of 23 is a two-player game that begins...Ch. 3 - Holy digits Batman! The Riddler is planning his...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Write a loop equivalent to the for loop above without using .
C Programming Language
Fill in the blanks in each of the following statements: A decision can be made in a Java program with a(n).
Java How To Program (Early Objects)
We have defined four binary logical connectives. a. Are there any others that might be useful? b. How many bina...
Artificial Intelligence: A Modern Approach
In Exercises 3 through 24, carry out the task. In Exercises 3 through 24, carry out the task. Create a label co...
Introduction To Programming Using Visual Basic (11th Edition)
John travels a distance of 55 miles at an average speed of 15 miles per hour. Write a program to calculate the ...
Absolute Java (6th Edition)
Property Tax A county collects property taxes on the assessment value of property, which is 60 percent of the p...
Starting Out with C++ from Control Structures to Objects (9th Edition)
Knowledge Booster
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
- This problem has you write a nested loop to process a list of list of int, and accumulate a list of list of int. The starter code provides an accumulator for the result and a loop over the lists, and you need to write the code that checks whether sublist contains only even ints. You'll probably want a one-way flag: a Boolean variable that starts out as True and is set to False if you find an odd int in the sublist. You'll need to check the value of this variable to figure out whether to append sublist to the even_lists accumulator. def only_evens(lst: list[list[int]]) -> list[list[int]]: """Return a list of the lists in lst that contain only even integers. >>> only_evens([[1, 2, 4], [4, 0, 6], [22, 4, 3], [2]]) [[4, 0, 6], [2]] """ even_lists = [] for sublist in lst: # write your code here (please read above for a suggested approach) return even_listsarrow_forwardIf we were to run the following program for the list = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1}, how many times do we execute the inner for loop? for (int i = 1; i < list.length; i++) { int currElement = list[i]; int k; for (k = i - 1; k >= 0 && list[k] > currElement; k--) { list[k + 1] = list[k]; } list[k+1] = currElement;}arrow_forwardWrite a program that reads a list of integers, and outputs whether the list contains all even numbers, odd numbers, or neither. The input begins with an integer indicating the number of integers that follow.arrow_forward
- Write a program in CORAL to accept a series of positive integers in a loop and then terminatethe loop once a negative value is read. Once the loop is terminated, display the largest andsmallest integer in the list.Hence, if the input were : 23 44 3 76 88 55 32 14 -5 what is the output.arrow_forwardWrite a program that first reads a list of 5 integers from input. Then, read another value from the input, and output all integers less than or equal to that last value. Ex: If the input is: 50 60 140 200 75 100 the output is: 50 60 75 For coding simplicity, follow every output value by a space, including the last one. Then, output a newline. Such functionality is common on sites like Amazon, where a user can filter results.arrow_forwardThe for loop iterates across the elements in a given list. Hence, it runs forever, provided there are still objects to process. Will this prove to be a true or untrue statement?arrow_forward
- Write a program that receives a list of integers and prints out that list after removing prime numbers from the list. Test your program with multiple lists of numbers and make sure it works properly. For instance, if the input is [1, 2, 3, 4, 5, 6, 7], it should print [1, 4, 6]. IN PYTHONarrow_forwardWrite a program that reads a list of integers into a list as long as the integers are greater than zero, then outputs the values of the list. You can assume that the list of integers will have at least 2 values. Can I get some help with finishing this? My code so far: user_numbers = [] while user_input >0: print (user_numbers)arrow_forwardin java Add a foreach loop at the end of the main method to print all the list elements side by side, separated by single spaces. Include a brief description so the output shows that these are the list elements printed with the foreach loop.arrow_forward
- Write a program that reads a list of integers into a list as long as the integers are greater than zero, then outputs the smallest and largest integers in the list. Ex: If the input is: 10 5 3 21 2 -6 the output is: 2 21 You can assume that the list of integers will have at least 2 values.arrow_forwardWrite a program in python that creates a list of your friends. Start with an empty list and then use a while loop to add friends to the list. This loop should repeat until you leave a name blank. Report the size of your list. You forgot a good friend. If she is not in the list (let code decide), she should be inserted at the start of the list. Use a for loop to display the names of your friends on one line, separated by spaces. A friend has moved away. Remove this friend by name from the list. Sort the list in alphabetical order and use another loop to display your friends, sorted. Sample OutputEnter the first name of a friend or ENTER to quit PennyEnter the first name of a friend or ENTER to quit LennyEnter the first name of a friend or ENTER to quit KennyEnter the first name of a friend or ENTER to quit DennyEnter the first name of a friend or ENTER to quit BennyEnter the first name of a friend or ENTER to quitYou made a list of 5 friends.OOPS, you forgot to enter a very good…arrow_forwardIn python: Write a program that first gets a list of integers from input. The input begins with an integer indicating the number of integers that follow. Then, get the last value from the input, which indicates a threshold. Output all integers less than or equal to that last threshold value. Ex: If the input is: 5 50 60 140 200 75 100 the output is: 50 60 75 The 5 indicates that there are five integers in the list, namely 50, 60, 140, 200, and 75. The 100 indicates that the program should output all integers less than or equal to 100, so the program outputs 50, 60, and 75. Such functionality is common on sites like Amazon, where a user can filter results.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
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)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Introduction to Big O Notation and Time Complexity (Data Structures & Algorithms #7); Author: CS Dojo;https://www.youtube.com/watch?v=D6xkbGLQesk;License: Standard YouTube License, CC-BY