0% found this document useful (0 votes)
3 views8 pages

Programming Logic: Loops and Algorithms

The document consists of a series of questions related to programming logic and algorithms, specifically focusing on loops, control variables, and their implementations in Python. Each question presents a scenario or code snippet and asks the reader to identify the correct statements or solutions related to the concepts learned in class. The document confirms the correctness of selected answers and provides feedback on the understanding of loop structures.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views8 pages

Programming Logic: Loops and Algorithms

The document consists of a series of questions related to programming logic and algorithms, specifically focusing on loops, control variables, and their implementations in Python. Each question presents a scenario or code snippet and asks the reader to identify the correct statements or solutions related to the concepts learned in class. The document confirms the correctness of selected answers and provides feedback on the understanding of loop structures.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Question 1/10 - Programming Logic and Algorithms

In CLASS 4 we learned about counter type variables and also


as accumulators within repetition loops. Below we have an example of
algorithm that works with these concepts:

cont = 5
soma = 0
whilecont <= 25:
soma = soma + count
cont = cont + 5
print(sum)
Regarding the algorithm presented and its functioning, select the alternative
CORRECT:
Note: 10.0

A In the code, line 5 could be replaced by the instruction cont += 1, without harming its function.
The correct would be cont += 5

B The control variable of the loop is the variable sum.


Control variable is the remaining variable.

C The algorithm presented aims to calculate and display on the screen the sum of all
You selected this alternative (C)
You got it right!

D The presented algorithm aims to calculate and display on the screen the sum of all
The step is 5.

E The variable contains an accumulator variable, while the variable sum is a counter.
Each concept is placed backward.

Question 2/10 - Programming Logic and Algorithms


In the while loop structure, the execution of one or more instructions of
a block, or loop, depends on a control condition checked at the beginning, or in
entry, of the loop. As long as the result of the condition remains true, the block of
instructions are executed, otherwise the jump occurs to the first line after this
block.
The figure below shows the flowchart of a while loop structure.

Observe the statements below:

I. In the while loop structure, the boolean expression is checked before


from the execution of the first instruction within the block.
II. In the while loop structure, if the boolean expression results in
FALSE the instructions inside the block are not executed.
III. In the while loop, if the execution condition is false in
at some point, the loop is interrupted so that the rest of the algorithm can proceed
execution.
IV. In the while loop structure, if the condition result is
TRUE, the instructions are executed and then the condition will be tested.
again.
V. The while loop implements a counter variable
implicitly within its structure.

Regarding the while structure, mark only the CORRECT ones:


Note: 10.0

A I, III, IV, and V, only.

B I, II, IV and V, only.

C I, II and III, only.

D I, II, III and IV only.


You selected this option (D)

You got it!


Statement V is the only incorrect one. The structure that implicitly implements a counter is the for(p

E I, II, III, IV and V.

Question 3/10 - Programming Logic and Algorithms


In LESSON 4 you learned to work with loops.
employee while also of the for. Regarding its characteristics, observe the
following statements

I - The structure works in the same way as the while, that is, while
a condition remains true, the loop continues executing.
II - The lasso is commonly used in situations where the number of iterations is
finished and well defined.
III - The loop works with an implicit loop control variable.
Regarding the statements presented, mark only the CORRECT ones:
Note: 10.0

A I, only.

B II, only.

C I and II only.

D I and III, only.


E I, II and III.
You selected this option (E)
You got it right!

Question 4/10 - Programming Logic and Algorithms


In CLASS 4 you learned to work with the structure of
repetition while. Below you will find a code with the while that should
display on the screen all values from 10 to 100.

x = 10
whilex <= 100:
print(x)
However, the presented code contains a problem. Mark the alternative that
Correctly explain what the problem is and the solution to it.
Note: 10.0

A The problem in the code is that the control variable is not being iterated, creating an infinite loop.
close. The solution to the problem is to remove the print line from the while loop, placing it
loop to iterate the control variable.

B The problem in the code is that the logical expression placed in the loop is incorrect. The solution for
loop for x >= 100.

C The problem in the code is that the control variable is not being iterated, creating an infinite loop.
Close. The solution to the problem is to change the loop condition to x >= 100.

D The problem in the code is that the control variable is not being iterated, creating an infinite loop.
Close. The solution to the problem is to add a line that increments the control variable.
inserted before oprint.

E The problem in the code is that the control variable is not being iterated, causing an infinite loop.
close. The solution to the problem is to add a line that increments the counter variable.
after the print.
You indicated this option (E)

You got it!

Question 5/10 - Programming Logic and Algorithms


In CLASS 4, you learned how to work with the laçofor. Suppose that
you need to print on the screen numeric values starting from 7 and printing
up to 25, in increments of 3.
Select the option that contains the loop to carry out what is being proposed in
statement.
Note: 10.0

A for i in range(26):
print(i)
B for i in range(7, 26):
print(i)

C for i in range(7, 25):


print(i)

D for i in range(7, 26, 3):


print(i)
You selected this option (D)

You got it!


This is correct, as remember that to go up to 25, we must put up to 26 because the for loop performs iterations to

E for i in range(7, 25, 3):


print(i)

Question 6/10 - Programming Logic and Algorithms


In CLASS 4 we learned to work with the instructions
break continued within the loops of repetition. On this subject, analyze the
following statements:

I - The instruction 'continue' is capable of making the loop ensure that the
the next iteration will happen, as it ignores the next logical test of the loop.
II - The break instruction is capable of making the loop return to its start, restarting it.
loop.
III - It is allowed to combine break structures within the same
loop
Regarding the statements presented, mark only the CORRECT ones:
Note: 10.0

A I, just.

B II, just.

C III, only.
You marked this alternative (C)
You got it right!

D I and III only.

E II and III only.

Question 7/10 - Programming Logic and Algorithms


(ADAPTED) We learned to work in CLASS 4 with repetition structures.
nested. Observe the following code that contains an example of this using
two loops
for i in range(10, 20):
for i in range(10, 20, 2):
print('{} + {} = {}'.format(i, j, i + j))
Regarding this code, indicate the alternative that contains a CORRECT statement.
about this code.
Note: 10.0

A The internal for loop will be executed 10 times during the entire execution of the program.
The inner loop runs 5 x 10 = 50 times

B The print of the result for i = 3 and j = 5 will be the value 2.


i+j=8

C If we changed the external loop to a while type, the line of code corresponds to the
it is also necessary to include two more lines for initialization and increment of the variable
You marked this alternative (C)
You got it right!
Correct. Of course, to work with the while it would be necessary to add two more lines, one
increasing. However, the requested line is correctly changed to a while

D The external loop works with a step of 20.


The step is unitary, as it was omitted.

E The internal loop works with a unit step.


Step is 2.

Question 8/10 - Programming Logic and Algorithms


In CLASS 4 we learned to build repetition loops using
whileefor.
Below you will find a code that is not being implemented with a loop.

x=5
print(x)
x += 5
print(x)
x += 5
print(x)
x += 5
print(x)
x += 5
print(x)

Result on the console screen:


5
10
15
20
25
Select the option that CORRECTLY solves the same problem and generates the
same output, but now using a while loop,
Python language.
Note: 10.0

A x=5
whilex <= 25:
print(x)
x += 5
You selected this option (A)
You got it right!

B x=5
while x < 25:
print(x)
x += 5

C while x <= 25:


print(x)
x += 5

D while x < 25:


print(x)
x += 5

E while x <= 25:


print(x)

Question 9/10 - Programming Logic and Algorithms


In CLASS 4 you learned the while loop and the for loop. Next, you are
I sell a bow implemented with comfort.

for i in range(100, 1000, 10):


print(i)
Select the option that CORRECTLY generates the same output as the code
presented, but now implementing with while loop.

Note: 10.0

A i = 100
while(i <= 1000):
print(i)
i += 10
B i = 100
while(i <= 999):
print(i)
i += 10
You selected this option (B)
You got it right!

C i = 99
while(i <= 1000):
print(i)
i += 10

D i = 99
while(i <= 999):
print(i)
i += 10

E i = 99
while(i <= 999):
print(i)

Question 10/10 - Programming Logic and Algorithms


In CLASS 4 we learned the concept of loop structure.
this content, analyze the following statements:

I - Loop structures have one of their objectives to assist in the reduction of


amount of redundant instructions in an algorithm.
II - Repetition structures are also called iterative structures, or loops.
of repetition.
III - A loop structure is a feature in programming that causes
all the instructions within it repeat indefinitely and/or until a
a certain condition is met.
IV - There is only one way to create loop structures in Python language.
what would be the structure called while (or as while in pseudocode).
Regarding the statements presented, mark only the alternative containing the
correct
Note: 10.0

A I and II, only.

B I, II and III, only.


You selected this option (B)

You got it!


Statement IV is incorrect because we have 2 loops in Python: while and for.

C I and III only.


D I and III and IV, only.

E I, II, III and IV.

You might also like