Chapter 2 checkpoint questions Flashcards

1
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
2
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
3
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
4
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
5
Q

What does the oval symbol mean in a flowchart?

A

Ovals are terminal symbols.

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

What does the parallellogram symbol mean in a flowchart?

A

Parallellograms are either output or input symbols.

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

What does the rectangle symbol mean in a flowchart?

A

Rectangles are processing symbols.

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

Write a statement that displays your name

A

print(“The name”)

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

Write a statement that displays the following text:

Python’s the best!

A

print(“Python’s the best!”)

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

Write a statement that displays the following text:

The cat said “meow.”

A

print(‘The cat said “meow.”’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
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
12
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
13
Q

Is the variable name Sales the same as sales? Why or why not?

A

No, variable names are case sensitive.

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

Is the following assignment statement valid or invalid? If it is invalid, why?

72 = amount

A

It is invalid, the variable that is receiving the assignment (in this case ‘amount’) must appear on the left side of the = operator.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
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
16
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

value1: int.
value2: float
value3: float
value4: int.
value5: str

17
Q

What will be displayed by the following program?

my_value = 99
my_value = 0
print(my_value)

18
Q

What value will be assigned to “result” after the following statement executes?

result = 9 // 2

A

4

(The floor division operator, also referred to as integer division operator. The resultant value is a whole integer, though the result’s type is not necessarily int.)

19
Q

What value will be assigned to “result” after the following statement executes?

result = 9 % 2

A

1

The Modulus operator returns the decimal part (remainder) of the quotient.

20
Q

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

A

If you don’t 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.

21
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.

22
Q

What is the ‘\n’ escape character?

A

It is the newline escape character.

23
Q

What does the + operator do when it is used with two strings?

A

It is the string concatenation operator, which joins two strings together.

24
Q

What does the statement print(format(65.4321, ‘2f’) display?

25
What does the statement print(format(987654.129, '2f') display?
978,654.13
26
What are three advantages of using named constants?
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.
27
Write a Python statement that defines a named constant for a 10 percent discount.
variableName = 0.1