Test 1 Flashcards

Chapter 1, 2, 3, 4 - Checkpoint Questions

1
Q

What is a program?

A

A program is a set of instructions that a computer follows to perform a task.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is hardware?

A

Hardware is all the physical devices, or components, of which a computer is made.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

List the five major components of a computer system?

A
  • CPU (central processing unit)
  • Main Memory
  • Secondary storage devices
  • Input devices
  • Output devices
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What part of the computer actually runs programs?

A

The CPU

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What part of the computer serves as a work area to store a program and its data while the program is running?

A

Main Memory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What part of the computer holds data for long periods of time, even when there is no power to the computer?

A

Secondary Storage

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What part of the computer collects data from people and from other devices?

A

Input devices

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What part of the computer formats and presents data for people or the devices?

A

Output devices

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What fundamental set of programs control the internal operations of the computer’s hardware?

A

The operating system

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What do you call a program that performs a specialized task, such as a virus scanner, a file compression program, or a data backup program?

A

A utility program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Word processing programs, spreadsheets programs, email programs, web browsers, and game programs belong to what category of software?

A

Application software

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What amount of memory is enough to store a letter of the alphabet or a small number?

A

One byte

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What do you call a tiny “switch” that can be set to either on or off?

A

A bit

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

In what numbering system are all numeric values written as sequences of 0s and 1s?

A

The binary numbering system

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the purpose of ASCII?

“American Standard Code for Information Interchange”

A

It is an encoding scheme that uses a set of 128 numeric codes to represent the English letters, various punctuation marks, and other characters. These numeric codes are used to store characters in a computer’s memory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What encoding scheme is extensive enough to represent the characters of many of the languages in the world?

A

Unicode

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What do the terms “digital data”and “digital device” mean?

A

Digital data is data that is stored in binary

Digital devices is any device that works with binary data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

A CPU understands instructions that are written only in what language?

A

Machine Language

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

A program has to be copied into what type of memory each time the CPU executes it?

A

Main Memory (RAM)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

When a CPU executes the instructions in the program, it is engaged in what process?

A

The fetch-decode-execute cycle

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What is assembly language?

A

It is an alternative to machine language. Instead of using binary numbers for instructions, assembly language uses short words that are known as mnemonics.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What type of programming language allows you to create powerful and complex programs without knowing how the CPU works?

A

A high-level language

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Each language has a set of rules that must be strictly followed when writing a program.
What is this set of rules called?

A

Syntax

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What do you call a program that translates a high-level language program into a separate machine language program?

A

A compiler

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

What do you call a program that both translates and executes the instructions in high-level language program?

A

An interpreter

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

What type of mistake is usually caused by a misspelled keyword, a missing punctuation character, or the incorrect use of an operator?

A

A syntax error

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

Who is a programmers customer?

A

Any person, group, or organization that is asking you to write a program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

What is a software requirement?

A

A single function that the program must perform in order to satisfy the customer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

What is an algorithm?

A

A set of well-defined logical steps that must be taken to perform a task

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

What is pseudocode?

A

An informal language that has no syntax rules and is not meant to be compiled or executed. Instead, programmers use pseudocode to create models, or “mock-ups,” of programs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

What is a flowchart?

A

A diagram that graphically depicts the steps that take place in a program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

What do the following symbols mean in a flowchart? Oval, Parallelogram, Rectangle

A

Ovals - terminal symbols
Parallelograms - are either output or input symbols
Rectangle- are processing symbols

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

What is a variable?

A

A name that references a value in the computer’s memory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

Which of the following are illegal variable names in Python, and why?
x
99bottles
July2009
theSalesFigureForFiscalYear
r&d
grade_report

A
  • 99bottles is illegal because it begins with a number
  • r&d is illegal because the & character is not allowed
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

What will the following code display?

-val=99

-print(‘The value is’, ‘val’)

A

The value is val

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q

Look at the following assignment statements:
-value1 = 99
-value2 = 45.9
-value3 = 7.0
-value4 = 7
-value5 = ‘abc’

After these statements execute, what is the Python data type of the values referenced by each variable?

A

-int
-float
-float
-int
-string

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q

What will be displayed by the following program?

-my_value = 99
-my_value = 0
-print(my_value)

A

0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
38
Q

You need the user of a program to enter a customer’s last name. Write a statement that prompts the user to enter this data and assigns the input to a variable.

A

last_name = input(“Enter customer’s last name: “)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
39
Q

You need the user of a program to enter the amount of sales for the week. Write a statement the prompts the user to enter this data and assigns the input to a variable.

A

sales = float(input(‘Enter the sales for the week: ‘))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
40
Q

Write the value of each expression?
1. 6+3*5
2. 12/2-4
3. 9+14 * 2 -6
4. (6+2) * 3
5. 14 / (11-4)
6. 9 + 12 * (8 -3)

A
  • 21
  • 2
    -31
    -24
    -2
    -69
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
41
Q

What value will be assigned?

Result = 9//2

A

4

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
42
Q

What value will be assigned?

Result = 9%2

A

1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
43
Q

What is string concatenation?

A

The appending of one string to the end of another

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
44
Q

What value will be assigned?

Results = ‘1’ + ‘2’

A

12

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
45
Q

What value will be assigned?

Result = ‘h’ ‘e’ ‘l’ ‘l’ ‘o’

A

hello

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
46
Q

How do you suppress the print function’s ending newline?

A

If you do not want the print function to start a new line of output when it finishes displaying its output, you can pass the special argument end = ‘ ‘ to the function

47
Q

How can you change the character that is automatically displayed between multiple items that are passed to the print function?

A

You can pass the argument sep = to the print function, specifying the desired character

48
Q

What is the ‘\n’ escape character?

A

It is the newline escape character

49
Q

In the following statement, what is the purpose of the number 10 in the format specifier?

-print(f’{name:10}’)

A

It is a field width designator. It indicates that the value should be displayed in a field that is a minimum of 10 spaces wide.

50
Q

In the following statement, what is the purpose of the number 15 in the format specifier?

-print(f’{number:15,d})

A

It is a field width designator. It indicates that the value should be displayed in a field that is a minimum of 15 spaces wide.

51
Q

In the following statement, what is the purpose of the number 8 in the format specifier?

-print(f’{number:8, .2f}’)

A

It is a field width designator. It indicates that the value should be displayed in a field that is a minimum of 8 spaces wide.

52
Q

What are these alignment designators?

<
>

A

Left- aligns

Right- aligns

Center- aligns

Placement Example: print(f’{number:>12d}’)

53
Q

What are 3 advantages of using names constants?

A

(1) Named constants make programs more self-explanatory
(2) widespread changes can easily be made to the program
(3) they help to prevent the typographical errors that are common when using magic numbers.

54
Q

Write a Python statement that defines a named constant for a 10 percent discount.

A

DISCOUNT_PERCENTAGE = 0.1

55
Q

A _______ error does not prevent the program from running, but causes it to produce incorrect results

A

Logic

56
Q

A ________ is a single function that the program must preform in order to satisfy the customer

A

software requirement

57
Q

A _____ is a sequence of characters

A

String

58
Q

A _______ is a name that references a value in the computer’s memory.

A

Variable

59
Q

A ______ is an any hypothetical person using a program and providing input for it.

A

User

60
Q

Short notes placed in different parts of a program explaining how those parts of the program work are called _______.

A

Comments

61
Q

A _______ makes a variable reference a value in the computers memory.

A

assignment statement

62
Q

In the expression 12 + 7, the values on the right and left of the + symbol are called _____.

A

Operands

63
Q

What operator performs integer division?

A

//

64
Q

What operator raises a number to a power?

A

**

65
Q

What operator performs decision, but instead of returning the quotient it returns the remainder?

A

%

66
Q

A string literal in Python must be enclosed in ____.

A

either single-quotes or double-quotes

67
Q

Computer programs typically perform what 3 steps?

A
  1. Input is received
  2. Some process is performed on the input
  3. Output is produced
68
Q

What is the difference between floating-point division and integer division?

A

Integer division gives result as a whole number while floating-point division is given as a decimal.

69
Q

What is a magic number? Why are magic numbers problematic?

A

A magic number is an unexplained value that appears in a program’s code.

  1. It can be difficult for someone reading the code to determine the purpose of the number
  2. If the magic number is used in multiple places in the program, it can take lots of effort to change the number in each location
  3. You take the risk of making a typographical mistake
70
Q

The computer stores a program while the program is running, as well as the data that the program is working with, in_____.

A

main memory?

71
Q

Negative numbers are encoded using the ____ technique

A

two’s complement

72
Q

Real Numbers are encoded using the ____ technique

A

floating point

73
Q

The _____ translates an assembly language program to a machine language program

A

assembler

74
Q

The words that make up a high-level programming language are called ______.

A

keywords or reserved words

75
Q

A _____________structure can execute a set of statements only under certain circumstances.

A

decision

76
Q

A(n) _____ expression has a value of either True or False.

A

Boolean

77
Q

The symbols >, <, and == are all ________operators.

A

relational

78
Q

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

dual alternative decision

79
Q

and, or, and not are _________operators.

A

logical

80
Q

The _________ operator takes a Boolean expression as its operand and reverses its logical value.

A

not

81
Q

A _________is a Boolean variable that signals when some condition exists in the program.

A

flag

82
Q

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

A

condition

83
Q

Each repetition of a loop is known as a(n) ________.

A

cycle

84
Q

The while loop is a _________type of loop.

A

pretest

85
Q

The -= operator is an example of a(n) _______operator.

A

augmented assignment

86
Q

A(n) ______is a special value that signals when there are no more items from a list of items to be processed. This value cannot be mistaken as an item from the list.

A

sentinel

87
Q

The integrity of a program’s output is only as good as the integrity of the program’s __________.

A

programming language

88
Q

The input operation that appears just before a validation loop is known as the ________.

A

priming read

89
Q

Validation loops are also known as __________ .

A

error trap

90
Q

3.1 What is a control structure?

A

A logical design that controls the order in which a set of statements execute

91
Q

3.2 What is a decision structure?

A

It is a program structure that can execute a set of statements only under certain circumstances.

92
Q

3.5 What types of relationships between values can you test with relational operators?

A

You can determine whether one value is greater than, less than, greater than or equal to, less than or equal to, equal to, or not equal to another value.

93
Q

3.6 Write an if statement that assigns 0 to x if y is equal to 20.

A

if y == 20:
 x = 0

94
Q

3.7 Write an if statement that assigns 0.2 to commissionRate if sales is greater than or equal to 10000.

A

if sales >= 10000:
commissionRate = 0.2

95
Q

3.9 What statement do you use in Python to write a dual alternative decision structure?

A

if-else

96
Q

3.10 When you write an if-else statement, under what circumstances do the statements that appear after the else clause execute?

A

When the condition is false

97
Q

3.14 What is a compound Boolean expression?

A

It is an expression that is created by using a logical operator to combine two Boolean subexpressions.

98
Q

3.17 Explain how short-circuit evaluation works with the and and or operators.

A

The and operator: If the expression on the left side of the and operator is false, the expression on the right side will not be checked.

The or operator: If the expression on the left side of the or operator is true, the expression on the right side will not be checked.

99
Q

3.18 Write an if statement that displays the message “The number is valid” if the value referenced by speed is within the range 0 through 200.

A

if speed >= 0 and speed <= 200:
print(‘The number is valid’)

100
Q

3.19 Write an if statement that displays the message “The number is not valid” if the value referenced by speed is outside the range 0 through 200.

A

if speed < 0 or speed > 200:
print(‘The number is not valid’)

101
Q

3.20 What values can you assign to a bool variable?

A

True or False

102
Q

3.21 What is a flag variable?

A

A variable that signals when some condition exists in the program

103
Q

4.4 What is a loop iteration?

A

An execution of the statements in the body of the loop

104
Q

4.5 Does the while loop test its condition before or after it performs an iteration?

A

Before

105
Q

4.6 How many times will ‘Hello World’ be printed in the following program?

count = 10
while count < 1:
print(‘Hello World’)

A

None. The condition count < 0 will be false to begin with.

106
Q

4.8 Rewrite the following code so it calls the range function instead of using the list [0, 1, 2, 3, 4, 5]:

for x in [0, 1, 2, 3, 4, 5]:
print(‘I love to program!’)

A

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

107
Q

4.9 What will the following code display?

for number in range(6):
print(number)

A

0
1
2
3
4
5

108
Q

4.10 What will the following code display?

for number in range(2, 6):
print(number)

A

2
3
4
5

109
Q

4.11 What will the following code display?

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

A

0
100
200
300
400
500

110
Q

4.12 What will the following code display?

for number in range(10, 5, −1):
print(number)

A

10
9
8
7
6

111
Q

4.14 Should an accumulator be initialized to any specific value? Why or why not?

A

Yes, it should be initialized with the value 0. This is because values are added to the accumulator by a loop. If the accumulator does not start at the value 0, it will not contain the correct total of the numbers that were added to it when the loop ends.

112
Q

4.15 What will the following code display?

total = 0
for count in range(1, 6):
total = total + count
print(total)

A

15

113
Q

4.16 What will the following code display?

number 1 = 10
number 2 = 5
number 1 = number 1 + number 2
print(number1)
print(number2)

A

15
5

114
Q

4.17 Rewrite the following statements using augmented assignment operators:

quantity = quantity + 1

days_left = days_left − 5

price = price * 10

price = price / 2

A

quantity += 1

days_left −= 5

price *= 10

price /= 2