SCRIPTING-AND-PROGRAMMING-FOUNDATIONS practice question 15 of 25
A program adds a service fee to the total cost of concert tickets when the tickets are printed and mailed to customers. Another service fee is also added if the tickets are delivered overnight. Which control structure should be used?
Full set: 137 questionsThe problem describes two separate, non-exclusive conditions. A fee is added for printed/mailed tickets, and another fee can be added for overnight delivery. A customer could have printed tickets sent via overnight delivery, meaning both conditions are true and both fees should apply. Multiple, independent if statements are required to check each condition separately. This ensures that each applicable fee is added to the total cost without precluding the other.
A: A while loop is an iteration structure used to repeat code while a condition is true, not for a one-time decision. B: A do-while loop is also for iteration and is inappropriate for this conditional logic. C: A single if statement (or an if-else structure) can only handle one condition or a set of mutually exclusive conditions.
- Gaddis, T. (2021). Starting Out with Programming Logic and Design (5th ed.). Pearson. Chapter 4, "Decision Structures and Boolean Logic," explains that multiple independent if statements are used when a series of non-exclusive decisions must be made.
- Zelle, J. M. (2017). Python Programming: An Introduction to Computer Science (3rd ed.). Franklin, Beedle & Associates. Chapter 7, "Decision Structures," illustrates how separate if statements allow for checking multiple conditions where more than one can be true.
- UC Berkeley, EECS Department. (n.d.). CS 61A: Structure and Interpretation of Computer Programs. Course materials on Control and Environments discuss the use of separate conditional statements for independent checks versus if-elif-else for mutually exclusive choices.
Keep practicing
Take the free SCRIPTING-AND-PROGRAMMING-FOUNDATIONS practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other SCRIPTING-AND-PROGRAMMING-FOUNDATIONS practice questions
- Question 1Which characteristic distinguishes a markup language from other languages?
- Question 2A program calculates the average miles per gallon given miles traveled and gas consumed H…
- Question 5Which characteristic specifically describes an object-oriented language?
- Question 6Which is one characteristic of an object-oriented language that is not a characteristic o…
- Question 7Which operation should be used to check if the difference of two values is greater than 1?
- Question 9A program allows the user to play a game. At the end of each game, the program asks the u…
