Chapter 2 Writing Sample Programs Flashcards
What are the 6 steps in the process of creating a program?
- Analyze the problem
- Determine Specifications
- Create a design
- Implement the design
- Test/Debug the program
- Maintain the program
What are some standards that Identifiers (Names) must follow when programming?
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.
What are the fragments of program code that produce or calculate new data values?
Expressions
What are strings?
Textual Data
A simple identifier can also be an expression. We use identifiers as variables to give names to values
ex:
»> X=5
T or F
A variable doesn’t need to be assigned a value before it is used within a program
False. A variable must be defined for it to have an effect. If it is not you will receive a name error.
T or F
Spaces are irrelevant within an expression
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.
Give an example of Concatenation is.
Concatenation is the combining of strings (adding)
EX:
»> “Bat” + “Man”
What is a bare print?
A bare print has no parameters, so it produces a blank line of output. “\n”
What would the following function do?
print ( “The answer is “, end=” “ )
print (3+4)
The function would print ‘ The answer is 7 ‘
The end=” “ allows for the output from the second statement to be placed there.
Give an example of an assignment statement.
identifier= expression
=
Name = Ashlyn
T or F
A variable can only be assigned a value once.
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.
What is a name for the process of automatic memory management?
Garbage Collecting
How can you allow a variable to be based off of an input?
= input()
How can you allow for input to be entered into a variable if you need numbers?
= eval (input ())
T or F
the eval (input) function is extremely powerful and safe to use in all forms of programming!
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.
What is Code Injecting?
injecting malicious code into the running program.
What’s an alternative form of the assignment statement?
Simultaneous Assignment, this allows us to calculate several values all at the same time.
EX:
<var>, = , </var>
What’s the most effective way to swap the values of variables?
Creating a temp variable and doing a three way swap.
temp = X
X = Y
Y = temp
What’s another way you can swap the values of variables?
X, Y = Y, X
bc the assignment is simultaneous it avoids wiping out on of the original values so this method works.
What is the simplest for of a loop?
A definite loop.
EX:
for i in range (10)
-Counted loop
True or False
The best way to write a program is to type in some code and then debug it until it works
False
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
X- Variable
*- operator
3.9- Literal
Fragments of code that produce or calculate new data values are called:
Expressions