Exam 1
Overview
- definition of computer science and applications
- Python interpreter, Python prompt, shell vs. file editor
- comments
- primitive types: integers, floating point numbers, strings, booleans
- naming objects, assignment statements, variables, expressions, keywords
- mathematical operators:
+, -, *, /, //, %, **
- relational operators:
<, <=, >, >=, ==, !=
- logical operators:
and, or, not
- using modules and functions provided by Python
print
turtle
module: how to import, create turtle, use functions on turtle forward
, goto
, right
/left
, position
, dot
, penup
, pendown
math
module: how to import, use functions sqrt
, use constant pi
.
random
module: how to import, use function random
- constructor, dereferencing and dot operator
- functions (function signature, function definition, parameters, how to call/invoke a function, return)
for
loops, 3 ways to call range
, loop variable, accumulator pattern
- if statements (
if
, elif
, else
), nested if statements
- approximating pi (Archimedes, Leibniz, Wallis, Monte Carlo)
I suggest you review chapters 1 & 2 from our book and all reading quizzes.
Our book, homework, and all in-class activities give you many examples that you can work through to practice.
Instructions for Exam
The exam will be conducted during class. It is closed book, no calculators, no computer, no electronics. You will have the duration of class time to finish the exam. It must be completed individually.
You may bring a single letter-sized sheet of handwritten notes. Write your name at the top – I will collect it. I suggest you write sparingly on the single note page that you may use, and continue to study vigorously for the exam. You will not have enough time to complete the exam if you rely too heavily on your single sheet of handwritten notes.
Questions are worth 1-3 points depending on their level of difficulty and number of subproblems. Questions have the following form.
- Multiple choice / true false. For example,
- Given a few lines of code which manipulate a variable, what is the value of a variable after all lines are executed?
- What is the result of the expression
((True or False) and False)
?
- Which of the following is the python prompt?
- Fill-in. For example,
- What is the value of a variable after all lines are executed?
- Given the following lines of code, what condition should be inside the if statement?
- What is the name of a term corresponding to the given definition/description?
- Short responses. For example,
- Write a function that uses a for loop to compute and return the sum of the first 10 even numbers (2+4+….+18+20).
- Describe what a given function does.
- Describe the difference between
==
and =
- Suppose you are provided the function definition for a function
getArea(radius)
which takes the radius of a circle and returns the area. Call/invoke this function to print the area of a circle with radius 3.
Exam 2
Instructions are the same as previous exam. I suggest you review chapters 3, 4, & 5 from our book, and reading quizzes 8-16. Our book, homework, and all in-class activities give you many examples that you can work through to practice.
Topics include:
- strings (concatenation, repetition, index, length, slice, membership, justification, upper/lower-case,
find
, replace
, ord
, chr
, str
, formatting) and immutability
- encryption and decryption using transposition or substitution cipher
- prompting for user input with
input
function
- lists (initialization, indexing, concatenation, reptition, membership, length, slicing,
append
, insert
, pop
, sort
, reverse
, index
, count
, remove
, list comprehension) and mutability
- dictionaries (
keys
, values
, items
, get
, membership, index operator, del
)
- tuples (e.g., what is returned from dictionary
items
)
- read from / write to files
- read from URLs, 4 components of URL (protocol, host, resource, parameters), definition of HTML,
- while loops, definition of infinite loop,
- statistics: definition of dispertion, central tendency measures such as mean, median, mode, frequency distribution, histogram,
min
and max
functions, Pearson correlation coefficient (the range and significance of value)
Instructions for Exam
The exam will be conducted during class. It is closed book, no calculators, no computer, no electronics. You will have the duration of class time to finish the exam. It must be completed individually.
You may bring a single letter-sized sheet of handwritten notes. I suggest you write sparingly on the single note page that you may use, and continue to study vigorously for the exam. You will not have enough time to complete the exam if you rely too heavily on your single sheet of handwritten notes.
Questions are worth 1-4 points depending on their level of difficulty and number of subproblems. Questions have the following form.
- Multiple choice / true false. For example,
- Given a few lines of code which manipulate a variable, what is the value of a variable after all lines are executed?
- Circle ALL of the code choices below which would result in the value
5
.
- Circle ALL of the statements below which are True.
- Which of the following lines of code will open a file for reading?
- Fill-in. For example,
- What is the value of a variable after all lines are executed?
- What will the following lines of code print out?
- Short responses. For example,
- Consider the following lines of code. What is output? If it would not run for some reason, explain.
- Write code that will keep asking the user to enter in a number. Once the user enters in a negative number, it should terminate and print the sum of all positive numbers entered. For example, if the user enters 1, 2, 3, and -1, then the program will output 6.