Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
4th Edition
ISBN: 9780134444321
Author: Tony Gaddis
Publisher: PEARSON
bartleby

Concept explainers

bartleby

Videos

Textbook Question
Chapter 4, Problem 1MC

A_________-controlled loop uses a true/false condition to control the number of times that it repeats.

a. Boolean

b. condition

c. decision

d. count

Expert Solution & Answer
Check Mark
Program Description Answer

The “while” loop is a condition-controlled loop; it controls the number of times that the loop repeats.

Hence, the correct answer is option “B”.

Explanation of Solution

Condition controlled loop:

This is a loop that exhibits true or false condition to control the number of times that the loop repeats. For example, the “while” loop is a condition-controlled loop.

  • The “while” loop first checks its expression, and then the statements inside the loop get executed. It is also called as pretest loops.
  • The loop gets terminated when the condition becomes false.

Syntax:

Syntax for the “while” loop is as follows:

  while boolean_expression:

  # while suite

Example Program:

Consider the following example of the condition-controlled loop:

#initialization of variable

a=1

#execute the while loop until a is less than or equal to 5

while a<=5:

         #Print the value of a

         print(a)

         #Increment a by 1 for each iteration of loop

         a+=1

zOutput:

1

2

3

4

5

In the above code, the “while” loop executes until the value of “a” is less than or equal to 5, and then it exits from the program when the condition inside the loop fails.

Explanation for incorrect options:

Boolean:

Boolean is not a loop instead it is a data type that is represented with two values either true or false. This value is based upon the flow of the action performed by the program.

Hence, option “A” is wrong.

Decision:

A decision is not a loop, and it decides the case to be executed based upon the situation.

Hence, option “C” is wrong.

Count controlled loop:

This is a loop that repeats a specific number of times, and it keeps track of the counter variable to track about the number of times that the loop executes. For example, “for” loop is a counter-controlled loop.

Hence, option “D” is wrong.

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
04:39
Students have asked these similar questions
1. In the first loop, the low number will be the starting point for the loop and thehigh will be the ending point. The loop should display the iterator number andthat number x 10 on the same line, separated by a tab. See example on p. 177.2. The second loop should accumulate all the numbers between the starting pointand ending point. You will need to create and initialize an accumulator such astotal before you start the loop.
True or False: You should be incrementing the control variable of a for loop True or False: you can use the control variable of a while loop after the loop has finished executing True or False: you can nest repetition structures in repetition structures True or False: you can nest selection structure in selection structures
A ______ value is a special value that is used to terminate a loop when a set of data is being entered. Select one: a. Break b. Marker c. Control d. Sentinel

Chapter 4 Solutions

Starting Out with Python (4th Edition)

Ch. 4.3 - What will the following code display? for number...Ch. 4.3 - What will the following code display? for number...Ch. 4.4 - Prob. 13CPCh. 4.4 - Should an accumulator be initialized to any...Ch. 4.4 - What will the following code display? total - 0...Ch. 4.4 - What will the following code display? number 1 =...Ch. 4.4 - Rewrite the following statements using augmented...Ch. 4.5 - Prob. 18CPCh. 4.5 - Why should you take care to choose a distinctive...Ch. 4.6 - What does the phrase garbage in, garbage out mean?Ch. 4.6 - Give a general description of the input validation...Ch. 4.6 - Describe the steps that are generally taken when...Ch. 4.6 - Prob. 23CPCh. 4.6 - If the input that is read by the priming read is...Ch. 4 - A_________-controlled loop uses a true/false...Ch. 4 - A _____-controlled loop repeats a specific number...Ch. 4 - Each repetition of a loop is known as a(n) a cycle...Ch. 4 - The while loop is a _______ type of loop. a....Ch. 4 - A(n) ______ loop has no way of ending and repeats...Ch. 4 - The -= operator is an example of a(n) _________...Ch. 4 - Prob. 7MCCh. 4 - A(n) ____________ is a special value that signals...Ch. 4 - Prob. 9MCCh. 4 - The integrity of a programs output is only as good...Ch. 4 - The input operation that appears just before a...Ch. 4 - Validation loops are also known as _________. a....Ch. 4 - A condition-controlled loop always repeats a...Ch. 4 - The while loop is a pretest loop.Ch. 4 - The following statement subtracts 1 from x: x = x ...Ch. 4 - It is not necessary to initialize accumulator...Ch. 4 - In a nested loop, the inner loop goes through all...Ch. 4 - To calculate the total number of iterations of a...Ch. 4 - The process of input validation works as follows:...Ch. 4 - What is a condition-controlled loop?Ch. 4 - What is a count-controlled loop?Ch. 4 - What is an infinite loop? Write the code for an...Ch. 4 - Why is it critical that accumulator variables are...Ch. 4 - What is the advantage of using a sentinel?Ch. 4 - Prob. 6SACh. 4 - What does the phrase garbage in, garbage out mean?Ch. 4 - Give a general description of the input validation...Ch. 4 - Write a while loop that lets the user enter a...Ch. 4 - Write a while loop that asks the user to enter two...Ch. 4 - Write a for loop that displays the following set...Ch. 4 - Write a loop that asks the user to enter a number....Ch. 4 - Write a loop that calculates the total of the...Ch. 4 - Rewrite the following statements using augmented...Ch. 4 - Write a set of nested loops that display 10 rows...Ch. 4 - Write code that prompts the user to enter a...Ch. 4 - Write code that prompts the user to enter a number...Ch. 4 - Bug Collector The Bug Collector Problem A bug...Ch. 4 - Calories Burned Running on a particular treadmill...Ch. 4 - Budget Analysis Write a program that asks the user...Ch. 4 - Distance Traveled The distance a vehicle travels...Ch. 4 - Average Rainfall Write a program that uses nested...Ch. 4 - Celsius to Fahrenheit Table Write a program that...Ch. 4 - Pennies for Pay Write a program that calculates...Ch. 4 - Sum of Numbers Write a program with a loop that...Ch. 4 - Ocean Levels Assuming the ocean's level is...Ch. 4 - Tuition Increase At one college, the tuition for a...Ch. 4 - Weight Loss If a moderately active person cuts...Ch. 4 - Calculating the Factorial of a Number In...Ch. 4 - Population Write a program that predicts the...Ch. 4 - Prob. 14PECh. 4 - Prob. 15PECh. 4 - Turtle Graphics: Repeating Squares In this...Ch. 4 - Turtle Graphics: Star Pattern Use a loop with the...Ch. 4 - Turtle Graphics: Hypnotic Pattern Use a loop with...Ch. 4 - Turtle Graphics: STOP Sign In this chapter, you...

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
Knowledge Booster
Computer Science
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
  • Basic while loop expression.   Write a while loop that prints userNum divided by 4 (integer division) until reaching 2 or less. Follow each number by a space. Example output for userNum = 160:40 10 2 Note: These activities may test code with different test values. This activity will perform four tests, with userNum = 160, then with userNum = 8, then with userNum = 0, then with userNum = -1. See "How to Use zyBooks".Also note: If the submitted code has an infinite loop, the system will stop running the code after a few seconds, and report "Program end never reached." The system doesn't print the test case that caused the reported message.
    A while loop reads characters from input. Write an expression that executes the while loop until character 's' is read. Ex: If the input is R X s, then the output is: User entered R User entered X Done #include <iostream>using namespace std; int main() {   char value;      cin >> value;      while (/* Your code goes here */) {      cout << "User entered " << value << endl;      cin >> value;   }      cout << "Done" << endl;      return 0;}
    Using c++Random Number Guessing Game Write a program that generates a random number between 1 and 100 and asks the user to guess what the number is. If the user’s guess is higher than the random number, the program should display “Too high. Try again.” If the user’s guess is lower than the random number, the program should display “Too low. Try again.” The program should use a loop that repeats until the user correctly guesses the random number. Then the program should display “Congratulations. You figured out my number.” Enhance the program so it keeps a count of the number of guesses the user makes. When the user correctly guesses the random number, the program should display the number of guesses along with the message of congratulations.
  • Qo9. Please create PYTHON expression executes a loop body but the user must enter a number not negative.consider this; if the code has an infinite loop, the system will say the program never reached..ex. inputs: 9 5 2 -1 Body Body Body Done.  user_num = int(input())while ''' this is where i dont know''':  print('Body')  user_num = int(input()) print('Done.').
    Using c++Random Number Guessing Game Write a program that generates a random number between 1 and 100 and asks the user to guess what the number is. If the user’s guess is higher than the random number, the program should display “Too high. Try again.” If the user’s guess is lower than the random number, the program should display “Too low. Try again.” The program should use a loop that repeats until the user correctly guesses the random number. Then the program should display “Congratulations. You figured out my number.”
    # NewMultiply.py - This program prints the numbers 0 through 10 along # with these values multiplied by 2 and by 10. # Input: None # Output: Prints the numbers 0 through 10 along with their values multiplied by 2 and by 10. head1 = "Number: " head2 = "Multiplied by 2: " head3 = "Multiplied by 10: " NUM_LOOP_START: = 2 # Constant used to control loop NUM_LOOP_END = 10 # Constant used to control loop print("0 through 10 multiplied by 2 and by 10.") # Write your for loop here for number in range(NUM_LOOP_START,NUM_LOOP_END): print(head1 +str (number)) print(head2 +str(number *2)) print(head3 +str(number *10))    it says line 10 needs to be fix im doing mindtap using loop in python  https://www.youtube.com/watch?v=TYSLiRruClk
  • Write a for loop that repeats seven times, asking the user to enter a number. The loop should also calculate the sum of the numbers entered and display the final sum.       Write a for loop that displays the following set of numbers:       0, 10, 20, 30, 40, 50 . . . 1000 What’s the initialization step? The Boolean test/condition? Update action/incrementation?     Convert the while loop in the following code segment to a for loop: int count = 0; while (count < 50) { System.out.println("count is " + count); count++; } please solve three of them
    LAB: Warm up: Text analyzer & modifier (1) Prompt the user to enter a string of their choosing. Output the string. (1 pt) Ex: Enter a sentence or phrase: The only thing we have to fear is fear itself. You entered: The only thing we have to fear is fear itself. (2) Complete the GetNumOfCharacters() function, which returns the number of characters in the user's string. We encourage you to use a for loop in this function. (2 pts) (3) In main(), call the GetNumOfCharacters() function and then output the returned result. (1 pt) (4) Implement the OutputWithoutWhitespace() function. OutputWithoutWhitespace() outputs the string's characters except for whitespace (spaces, tabs). Note: A tab is '\t'. Call the OutputWithoutWhitespace() function in main(). (2 pts) Ex: Enter a sentence or phrase: The only thing we have to fear is fear itself. You entered: The only thing we have to fear is fear itself. Number of characters: 46 String with no whitespace: Theonlythingwehavetofearisfearitself.
    Which kind of while loop may be broken by entering a single character or a single value into the input field? Although the loop eof, loop counter, and loop flag may all be managed, the loop sentinel cannot.
    • SEE MORE QUESTIONS
    Recommended textbooks for you
  • Programming Logic & Design Comprehensive
    Computer Science
    ISBN:9781337669405
    Author:FARRELL
    Publisher:Cengage
    Microsoft Visual C#
    Computer Science
    ISBN:9781337102100
    Author:Joyce, Farrell.
    Publisher:Cengage Learning,
    EBK JAVA PROGRAMMING
    Computer Science
    ISBN:9781337671385
    Author:FARRELL
    Publisher:CENGAGE LEARNING - CONSIGNMENT
  • Programming with Microsoft Visual Basic 2017
    Computer Science
    ISBN:9781337102124
    Author:Diane Zak
    Publisher:Cengage Learning
  • Programming Logic & Design Comprehensive
    Computer Science
    ISBN:9781337669405
    Author:FARRELL
    Publisher:Cengage
    Microsoft Visual C#
    Computer Science
    ISBN:9781337102100
    Author:Joyce, Farrell.
    Publisher:Cengage Learning,
    EBK JAVA PROGRAMMING
    Computer Science
    ISBN:9781337671385
    Author:FARRELL
    Publisher:CENGAGE LEARNING - CONSIGNMENT
    Programming with Microsoft Visual Basic 2017
    Computer Science
    ISBN:9781337102124
    Author:Diane Zak
    Publisher:Cengage Learning
    Control Structures - while loop - do-while loop - for loop - Goto - break - continue statements; Author: EzEd Channel;https://www.youtube.com/watch?v=21l11_9Osd0;License: Standard YouTube License, CC-BY