SCRIPTING-AND-PROGRAMMING-FOUNDATIONS practice question 2 of 25
A program calculates the average miles per gallon given miles traveled and gas consumed How should the item that holds me miles per gallon be declared?
Full set: 137 questionsThe value for miles per gallon is calculated by the program based on user input (miles traveled and gas consumed). Since this value is computed during program execution and can change with different inputs, it must be stored in a variable. A constant is used for values that do not change. The result of division is often a decimal number, making float the appropriate data type to handle fractional values accurately. The name milesPerGallon clearly describes the data being stored.
A. The item should be a variable, not a constant, and milesTraveled is an input, not the calculated result.
C. The name milesTraveled is incorrect; the variable should hold the calculated miles per gallon.
D. The item must be a variable because its value is calculated and will change, not a constant.
1. Severance, C. R. (2016). Python for Everybody: Exploring Data Using Python 3. Chapter 2, "Variables, expressions, and statements," explains the concept of variables for storing values that can change.
2. MIT OpenCourseWare. (2016). 6.0001 Introduction to Computer Science and Programming in Python. Fall 2016. Lecture 1, "What is Computation?", introduces the distinction between fixed constants and variables that store results of computations.
3. The C++ Core Guidelines. (n.d.). Con: Constants and Immutability. Retrieved from https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#S-const (This resource, while for C++, explains the universal programming principle of using constants for unchanging values and variables for calculated results.)
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 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…
- Question 10Which phase of an agile application would create a function that calculates shipping cost…
