Review Questions

Multiple Choice

1. A __— structure can execute a set of statements only under certain circumstances.

a. sequence b. circumstantial c. decision d. Boolean

2. A___structure provides one alternative path of execution.

a. sequencE

ternative decision c. one path alter*iaiive d. singli^Secution decision:

3. A(n)____ expression has a value of either true or false.

a. binary b. decision c. unconditional d. Boolean

4. The symbols >, <, and == are all_operators.

a. relational b. logical c. conditional d. ternary

5. A{n)_structure tests a condition and then takes one path if the condition is true, or another path if the condition is false.

a. if statement b. single alternative decision c. dual alternative decision d. sequence

6. You use a(n)_statement to write a single alternative decision structure.

7. You use a(n)_statement to write a dual alternative decision structure.

a. relational b. logical c. conditional d. ternary

9. A compound Boolean expression created with the_operator is true only if both of its subexpressions are true.

10, A compound Boolean expression created with the_operator is true if either of its subexpressions is true.

11, The_operator takes a Boolean expression as its operand and reverses its logical value, a. and b. or c. not d. either

12. A_ is a Boolean variable that signals when some condition exists in the program.

a. flag b. signal c. senrinel d. siren

True or False

1. You can write any program using only sequence structures.

2. A program can be made of only one type of control structure. You cannot combine structures.

3. A single alternative decision structure tests a condition and then takes one path if the condition is true, or another path if the condition is false.

4. A decision structure can be nested inside another decision structure-

5. A compound Boolean expression created with the and operator is true only when both subexpressions are true.

Short Answer

1. Explain what is meant by the term "conditionally executed."

2. You need to test a condition and then execute one set of statements if the condition is true. If the condition is false, you need to execute a different set of statements. What structure will you use?

3. Briefly describe how the and operator works.

4. Briefly describe how the or operator works.

5. When determining whether a number is inside a range, which logical operator is it best ro use?

6. What is a Hag and how does it work? Algorithm Workbench

1. Wrire an if statement that assigns 20 to the variable y and assigns 40 to the variable z if the variable x is greater than 100.

2. Write an if statement that assigns 0 to the variable b and assigns 1 to the variable c if the variable a is less than 10.

3. Write an if-else statement that assigns 0 ro the variable b if the variable a is less than 10. Otherwise, it should assign 99 to the variable b.

4. The following code contains several nested if-else statements. Unfortunately, it was written without proper alignment and indentation. Rewrite the code and use the proper conventions of alignment and indentation.

print 'Your grade is F.'

else:

print 'Your grade is D.1

else:

print "Your grade is C.'

else:

print 'Your grade is B.'

else:

print 'Your grade is A.'

5. Write nested decision structures that perform the following: If amountl is greater than 10 and amount2 is less than 100, display the greater of amountl and araount2.

6. Write an if-else statement that displays ' Speed is normal' if the speed, variable ts within the range of 24 to 56. It the speed variable's value is outside this range, display 1 Speed is abnormal'.

7. Write an if-else statement that determines whether the points variable is outside the range of 9 to 51. If the variable's value is outside this range it should display "Invalid points." Otherwise, Lt should display "Valid points."

0 0

Responses

  • Taneli
    What is meant by the term conditionally executed?
    7 years ago
  • fatima white
    What statement do you use in python to write a dual alternative decision structure?
    7 years ago
  • kiros
    When determining whether a number is outside certain range is best to use whichlogical operator?
    7 years ago
  • petra schwartz
    What structure can execute a set of statements only under certain circumstances?
    7 years ago
  • Andreas Hueber
    What is an compound Boolean expression?
    6 years ago
  • Harry Burns
    When determining wheather a number is inside a range which logical operator is it best use?
    6 years ago

Post a comment