Chapter 2 Writing Sample Programs Flashcards

1
Q

What are the 6 steps in the process of creating a program?

A
  1. Analyze the problem
  2. Determine Specifications
  3. Create a design
  4. Implement the design
  5. Test/Debug the program
  6. Maintain the program
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are some standards that Identifiers (Names) must follow when programming?

A

The must all begin with a letter or and underscore character, and they can be followed by any sequence of letters or numbers. There can be no spaces in these names.

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

What are the fragments of program code that produce or calculate new data values?

A

Expressions

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

What are strings?

A

Textual Data

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

A simple identifier can also be an expression. We use identifiers as variables to give names to values

A

ex:
»> X=5

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

T or F
A variable doesn’t need to be assigned a value before it is used within a program

A

False. A variable must be defined for it to have an effect. If it is not you will receive a name error.

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

T or F
Spaces are irrelevant within an expression

A

True. While spaces won’t effect if your code works or not, spaces can make a difference in how easily you can read an expression.

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

Give an example of Concatenation is.

A

Concatenation is the combining of strings (adding)

EX:
»> “Bat” + “Man”

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

What is a bare print?

A

A bare print has no parameters, so it produces a blank line of output. “\n”

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

What would the following function do?

print ( “The answer is “, end=” “ )
print (3+4)

A

The function would print ‘ The answer is 7 ‘
The end=” “ allows for the output from the second statement to be placed there.

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

Give an example of an assignment statement.

A

identifier= expression
=
Name = Ashlyn

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

T or F
A variable can only be assigned a value once.

A

False! A variable can be redefined as much as you want to change it. The variable will take the values that was assigned most recently. Variables are called variables because they are ( can ) constantly changing.

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

What is a name for the process of automatic memory management?

A

Garbage Collecting

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

How can you allow a variable to be based off of an input?

A

= input()

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

How can you allow for input to be entered into a variable if you need numbers?

A

= eval (input ())

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

T or F
the eval (input) function is extremely powerful and safe to use in all forms of programming!

A

False. It can be extremely dangerous if the input ability falls into the hands of an experienced hacker who would be able to code inject.

17
Q

What is Code Injecting?

A

injecting malicious code into the running program.

18
Q

What’s an alternative form of the assignment statement?

A

Simultaneous Assignment, this allows us to calculate several values all at the same time.
EX:
<var>, = , </var>

19
Q

What’s the most effective way to swap the values of variables?

A

Creating a temp variable and doing a three way swap.
temp = X
X = Y
Y = temp

20
Q

What’s another way you can swap the values of variables?

A

X, Y = Y, X
bc the assignment is simultaneous it avoids wiping out on of the original values so this method works.

21
Q

What is the simplest for of a loop?

A

A definite loop.
EX:
for i in range (10)
-Counted loop

22
Q

True or False
The best way to write a program is to type in some code and then debug it until it works

A

False

23
Q

Given the following line of python code, match each part (on the left) with the descriptive term for that part (on the right):

x = x * 3.9

X
*
3.9

A

X- Variable
*- operator
3.9- Literal

24
Q

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

A

Expressions