1.A _____ -controlled loop uses a true/false condition to control the number oftimes that it repeats.A) BooleanB) conditionC) decisionD) countTable for Individual Question Feedback Points Earned:1.0/1.0Correct Answer(s):B Show
Correct2.A _____ -controlled loop repeats a specific number of times.1.0/1.0D Get answer to your question and much more
Correct3.Each repetition of a loop is known as a(n) _____ .1.0/1.0D Get answer to your question and much more Correct4.The while loop is a _____ type of loop.1.0/1.0A Get answer to your question and much more Correct5.A(n) _____ loop has no way of ending and repeats until the program isinterrupted.A) indeterminateB) interminableC) infiniteD) timelessTable for Individual Question Feedback Points Earned:1.0/1.0Correct Answer(s):C A __ controlled loop uses a true/false condition to control the number of times that it repeats A ___ controlled loop repeats a specific number of times. Each repetition of a loop is known as an The while loop is a ___ type of loop The Do-While loop is a __ type of loop. The for loop is a ___ type of loop. An__ loop has no way of ending and repeats until the program is interrupted. A ___ loop always executes at
least once. A___ variable keeps the running total A __ is a special value that signals when there are no more items from a list of items to be processed. This value cannot be mistaken as an item from the list. Control Structures - RepetitionRepetition Statements
while loops
Examples# This program calculates sales commissions. # Create a variable to control the loop. keep_going = 'y' # Calculate a series of commissions. while keep_going == 'y': # Get a salesperson's sales and commission rate. sales = float(input('Enter the amount of sales: ')) comm_rate = float(input('Enter the commission rate: ')) # Calculate the commission. commission = sales * comm_rate # Display the commission. print 'The commission is $%.2f' % commission # See if the user wants to do another one. keep_going = raw_input('Do you want to calculate another ' + \ 'commission (Enter y for yes): ') Code: commission.py In all but some rare cases, loops must contain within themselves a way to terminate. Something in the loop usually makes the test condition false. When this is missing the loop is called an infinite loop. You have to interrupt the program to exit an infinite loop. Avoid infinite loops most of the time. # This program demonstrates an infinite loop. # Create a variable to control the loop. keep_going = 'y' # Warning! Infinite loop! while keep_going == 'y': # Get a salesperson's sales and commission rate. sales = float(input('Enter the amount of sales: ')) comm_rate = float(input('Enter the commission rate: ')) # Calculate the commission. commission = sales * comm_rate # Display the commission. print 'The commission is $%.2f' % commission Code: infinite.py The for loop
Examples of for loopsExample: # This program demonstrates a simple for loop # that uses a list of numbers. print('I will display the numbers 1 through 5.') for num in [1, 2, 3, 4, 5]: print num Output: I will display the numbers 1 through 5. 1 2 3 4 5 Example: # This program also demonstrates a simple for # loop that uses a list of numbers. print('I will display the odd numbers 1 through 9.') for num in [1, 3, 5, 7, 9]: print(num) Output: I will display the odd numbers 1 through 9. 1 3 5 7 9 Example: # This program also demonstrates a simple for # loop that uses a list of strings. for name in ['Winken', 'Blinken', 'Nod']: print name Output: Winken Blinken Nod Using the range function with the for loop
What controlled loop uses a true false?A condition-controlled loop uses a true/false condition to control the number of times that it repeats. This contrasts with a count-controlled loop that repeats a specific number of times.
What type of loop repeats a specific number of times?A count-controlled loop repeats a specific number of times.
Which type of loop uses a Boolean expression to control the number of times a loop repeats?In a For loop, the programmer should know the exact number of iterations the loop must perform before writing the code. The While loop gets its name from the way it works: While a condition is false, do some task. The conditions that control a loop repetition are Boolean expressions.
What is a condition controlled loop?Condition Controlled Loops. ∎ A condition controlled loop is programming structure that. causes a statement or set of statements to repeat as long as a. condition evaluates to True.
|