Uploaded by social social

Exam 1 Review

advertisement
Exam 1 Review – Chapters 1 through 5
of Gaddis Fourth Edition
 Definitions
 Types
 Syntax
 If statements
 For loops
 While loops
 Functions
 Study labs 0, 1, 2, 3, 4 – requirements document and your
code
 Study project 1 – requirements documents and your code
Definitions
 Computer
 A machine that executes algorithms
 Hardware components: keyboard, CPU, RAM, monitor.
 Algorithm
 A series of step-by-step instructions
 Similar to a recipe
 IPO
 Input-process-output
 The basic pattern of the programs we have seen so far
 Identifier
 A name for a variable
Definitions
 Keyword
 An identifier reserved for use by Python
 Know examples
 Syntax
 The form of a language
 The rules for what parts go where
 Semantics
 The meaning of a construct
 Study Appendix C – ASCII codes
Types
 Know the basic types and what sorts of values make them up
 int
 float
 Boolean
 string
 Be able to create and use variables of these types
Types
 Know the operators, and how they affect the different types
 Arithmetic
 +, -, *, /
 Integer
 //, %
 When integers and floats are mixed together, the result will
be a float
Syntax
 Be able to write code using the constructs we have seen
 Assignment statements
 Including incrementing
 Getting input
 Use float(input(…) ) or int(input(…)) or input(…)
 Printing
 print(…)
 format within print
If-statements
 Be able to read and write if statements
 Simple if
if <cond>:
<body>
 If-else
if <cond>:
<body>
else:
<body>
If-statements
 If-elif
if <cond1>:
<body1>
elif <cond2>:
<body2>
 If-elif-else (aka multi-way)
if <cond1>:
<body1>
elif <cond2>:
<body2>
else:
<body3>
For Loops
 Be able to write a for loop
 The loop variable
 The range construct
 Know the for loop forms
 Counting
 Summing
 Be able to turn a for loop into a while loop, and vice-versa
While Loops
 Know the forms of while loops
 Counting loops
 Summing loops
 Interactive loops
 Sentinel loops
 Use of a break statement to end a loop
While Loops
 In general, for any loop, know the four parts
Initialization
1.

Variables get values
Test
2.

Should the loop body execute one more time?
Body
3.

Where the work gets done
Update
4.

Change the control variable for the next time through the
loop
Functions
 Be able to
 Define a function
 Call a function
 Return a value from a function
 Declare and use parameters
 Turn a block of code into a function
 Parameters
 Formal
 Actual
 Know the relationship between them
Functions
 Know what happens during a function call
The program stops (suspends execution)
2. The parameters are passed
1.


The formal parameters of the function get assigned the values
supplied by the actual parameters in the call are copied into
the actual parameters
This is pass by value
The body of the function is executed
4. The return statement allows the program to pick back up
where it left off
3.
Download