Programming Review Part 1

¡Supera tus tareas y exámenes ahora con Quizwiz!

Consider the following code segment. What are the contents of yourList after the code segment is executed? A. [10, 30, 50, 70] B. [20, 40, 60, 80] C. [10, 30, 50, 70, 20, 40, 60, 80] D. [20, 40, 60, 80, 10, 30, 50, 70]

A

The variable isOpen is to be used to indicate whether or not a store is currently open. Which of the following the most appropriate data type for isOpen? A. Boolean B. number C. string D. list

A

Which of the following is a beenfit of using a list as a data abstraction in a program? A. Lists often allow their size to be easily updated to hold as many data values as needed B. Lists converts all elements to strings so that they can be inspected character-by-character C. List prevent duplicate data values from appearing in the list D. Lists are used to store all input data so that there is a running record of all user input

A

Consider the following code segment, which uses the varibales r, s, and t. r <-- 1 s <--2 t <-- 3 r <--s S <--t DISPLAY (r) DISPLAY (s) What is displayed as a result of running ther code segment? A. 1 1 B. 1 2 C. 2 3 D. 3 2

C

Consider the following code segment. x <--23 z <-- x MOD y Which of the following initial values of the variable y would result in the variable z being set to 2 after the code segment is executed? A. 1 B. 2 C. 3 D. 4

C

A programmer has a need to round many number values to the nearest integer. Which of the following best explains the benefit of using a list as a data abstraction in this situation? A. Keeping the numeric values in a list makes it easier to round a number to the nearest integer B. Keeping the number values in a list makes it easier to apply the same computation to every data element C. Keeping the numeric values in a list makes it easier to prevent a program from unintentionally changing the value of a variable D. Keeping the number values in a list makes it easier to prevent a program from attempting to access an index beyond the length of the list

B

Consider the following code segment. firstList ← ["guitar", "drums", "bass"] secondList ← ["flute", "violin"] thirdList ← [ ] thirdList ← firstList firstList ← secondList secondList ← thirdList What are the contents of secondList after the code segment is executed? A. [ ] B. ["guitar", "drums", "bass"] C. ["flute", "violin"] D. ["flute", "violin", "guitar", "drums", "bass"]

B

The variable age is to be used to represent a person's age, in years. Which of the following is the most appropriate data type for age? A. Boolean B. number C. string D. list

B

Direction: For the question or incomplete statement below, two of the suggested answers are correct. For this question, you must select both correct choices to earn credit. No partial credit will be earned if only one correct choice is selected. Select the two that are best in each case. Which of the following are benefits of using well-named variables in a computer program? A. The program will run faster B. The program will be easier for people to read C. The program will have a greater data storage capacity D. The program will be easier to modify in the future

B and D

Assume that both lists and strings are indexed starting with index 1. The list wordList has the following contents. ["abc", "def", "ghi", "jkl"] Let myWord be the element at index 3 of wordList. Let myChar be the character at index 2 of myWord. What is the value of myChar ? A. "e" B. "f" C. "h" D. "i"

C

A teacher is writing a code segment that will use variables to represent a student's name and whether or not the student is currently absent. Which of the following variables are most appropriate for the code segment? A. A string variable named s and a Boolean variable named a B. A string variable named s and a number variable named n C. A string variable named studentName and a Boolean variable isAbsent D. A string variable named studentName and a numeric variable named numAbsences

C

The code fragment below is intended to display "odd" if the positive number num is odd. Which of the following can be used to replace <MISSING CONDITION> so that the code fragment will work as intended? A. (num MOD 1) = 0 B. (num MOD 1) = 1 C. (num MOD 2) = 0 D. (num MOD 2) = 1

D

Which of the following code segments can be used to interchange the values of the variables num1 and num2 ? A. num1 <-- num2 num2 <-- num1 B. temp <--num1 num1 <-- temp num2 <-- num1 C. temp <--num1 num2 <-- 1 num1 <-- temp D. temp <--num1 num1 <-- 2 num2 <-- temp

D temp <--num1 num1 <-- 2 num2 <-- temp


Conjuntos de estudio relacionados

syllabus quiz questions and answers

View Set

Yoga- Surya Namaskara (Sun salutation A)

View Set

chapter 5 film appreciation test

View Set

Nursing Management: Patients With Structural, Inflammatory, and Infectious Cardiac Disorders

View Set

BUS 258 Compensation and Benefits MINE

View Set