0% found this document useful (0 votes)
5 views3 pages

Question

The document explains various programming concepts related to control structures, including decision structures, loops, and variables. It defines key terms such as Boolean expressions, flag variables, and accumulators, while providing examples of code and expected outputs. Additionally, it discusses specific types of loops like condition-controlled and count-controlled loops, as well as concepts like sentinels and priming reads.

Uploaded by

danteyda17
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Question

The document explains various programming concepts related to control structures, including decision structures, loops, and variables. It defines key terms such as Boolean expressions, flag variables, and accumulators, while providing examples of code and expected outputs. Additionally, it discusses specific types of loops like condition-controlled and count-controlled loops, as well as concepts like sentinels and priming reads.

Uploaded by

danteyda17
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Question: What is a control structure?

Answer: A control structure is a logical design that controls the order in which a set of statements
execute.

Question: What is a decision structure?


Answer: A decision structure executes a set of statements only under certain circumstances.

Question: What is a single alternative decision structure?


Answer: A single alternative decision structure provides one path of execution if the tested condition
is true.

Question: What is a Boolean expression?


Answer: A Boolean expression is an expression that evaluates to either true or false.

Question: Write an if statement that assigns 0.2 to commission Rate if sales is greater than or equal
to 10,000.
Answer:

if sales >= 10000:

commission Rate = 0.2

Question: What is a flag variable?


Answer: A flag variable signals when some condition exists in a program.

Question: What is a repetition structure?


Answer: A repetition structure is a structure that causes a section of code to repeat.

Question: What is a condition-controlled loop?


Answer: A condition-controlled loop is a loop that uses a true/false condition to control the number
of times it repeats.

Question: What is a count-controlled loop?


Answer: A count-controlled loop is a loop that repeats a specific number of times.

Question: What is a loop iteration?


Answer: A loop iteration is an execution of the statements in the body of the loop.

Question: What is an infinite loop?


Answer: An infinite loop is a loop that has no way of stopping and repeats until the program is
interrupted.
Question: Rewrite the following code using the range function:

for x in [0, 1, 2, 3, 4, 5]:

print('I love to program!')

Answer:

for x in range(6):
print('I love to program!')

Question: What will the following code display?

for number in range(6):

print(number)

Answer:

Question: What will the following code display?

for number in range(2, 6):

print(number)

Answer:

Question: What will the following code display?

for number in range(0, 501, 100):

print(number)

Answer:

100

200

300

400

500
Question: What will the following code display?

for number in range(10, 5, -1):

print(number)

Answer:

10

Question: What is an accumulator?


Answer: An accumulator is a variable used to accumulate the total of a series of numbers.

Question: What will the following code display?

total = 0

for count in range(1, 6):

total = total + count

print(total)

Answer:

15

Question: What is a sentinel?


Answer: A sentinel is a special value that marks the end of a list of items.

Question: What is a priming read? What is its purpose?


Answer: A priming read is the input operation performed before an input validation loop. Its
purpose is to get the first input value.

You might also like