2. Writing Simple Programs Flashcards

1
Q

True or False

The best way to write a program is to immediately type in some code and then debug it until it works.

A

False

We need a systematic approach.

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

True or False

An algorithm can be written without using a programming language.

A

True

Pseudocode is just precise English that describes what a program does. It is meant to communicate algorithms without all the extra mental overhead of getting the details right in any particular programming language.

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

True or False

Programs no longer require modification after they are written and debugged.

A

False

Most programs are never really finished; they keep evolving over years of use.

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

True or False

Python identifiers must start with a letter or underscore.

A

True

Every identifier must begin with a letter or underscore which may be followed by any sequence of letters, digits, or underscores. This implies that a single identifier cannot contain any spaces.

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

True or False

Keywords make good variable names.

A

False

These names are called reserved words or keywords and cannot be used as ordinary identifiers.

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

True or False

Expressions are built from literals, variables, and operators.

A

True

Expressions are the fragments of a program that produce data. An expression can be composed of literals, variables and operators.

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

True or False

In Python, x = x + 1 is a legal statement.

A

True

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

True or False

Python does not allow the input of multiple values with a single statement.

A

False

Python also allows simultaneous assignment, which is useful for getting multiple input values with a single prompt.

, , … = , , …,

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

True or False

A counted loop is designed to iterate a specific number of times.

A

True

One important use of a for statement is in implementing a counted loop, which is a loop designed specifically for the purpose of repeating some portion of the program a specific number of times. A counted loop in Python is created by using the built-in range function to produce a suitably sized sequence of numbers.

for <var> in :
</var>

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

True or False

In a flowchart, diamonds are used to show statement sequences, and rectangles are used for decision points.

A

False

Rectangles are used to show statement sequences, and diamonds are used for decision points.

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

Which of the following is not a step in the software development process?

a) specification
b) testing/Debugging
c) fee setting
d) maintenance

A

c) fee setting

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

The process of describing exactly what a computer program will do to solve a problem is called

a) design
b) implementation
c) programming
d) specification

A

d) specification

Program Specification: Deciding exactly what the program will do.

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

Which of the following is not a legal identifier?

a) spam
b) spAm
c) 2spam
d) spam 4U

A

d) spam 4U

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

Which of the following are not used in expressions?

a) variables
b) statements
c) operators
d) literals

A

b) statements

statements are built from identifiers and expressions.

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

Fragments of code that produce or calculate new data values are called

a) identifiers
b) expressions
c) productive clauses
d) assignment statements

A

b) expressions

Expressions are the fragments of a program that produce data.

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

Which of the following is not a part of the IPO pattern?

a) input
b) program
c) process
d) output

A

b) program

IPO : input, process, output pattern

17
Q

The template for in range ( ) describes

a) a general for loop
b) an assignment statement
c) a flowchart
d) a counted loop

A

d) a counted loop

One important use of a for statement is in implementing a counted loop, which is a loop designed specifically for the purpose of repeating some portion of the program a specific number of times. A counted loop in Python is created by using the built-in range function to produce a suitably sized sequence of numbers.

18
Q

Which of the following is the most accurate model of assignment in Python?

a) sticky-note
b) variable-as-box
c) simultaneous
d) plastic-scale

A

a) sticky-note

Assigning a variable is like putting one of those little yellow sticky notes on the value and saying, “this is x.”

19
Q

In Python, getting user input is done with a special expression called

a) for
b) read
c) simultaneous assignment
d) input

A

d) input

The eval function can be used to evaluate user input.

eval(input())