Quiz 2 Information
Quiz details
-
Quiz 2 will be held on Friday 5/29, beginning promptly at 9:30am.
-
The quiz will be on paper, and you will be expected to write/explain some code that is similar to work you did in the problem set.
-
Expect 2 short questions.
You will have 20 minutes for the quiz including.
-
This quiz is closed notes/closed books, and without any use of reference materials. No computers, phones, AI glasses, or other electronic devices are permitted.
-
There are some sample/pratice questions at the bottom of this page.
Material covered
The quiz will focus on the material that we have covered in module 1 and problem set 1. You must be familiar with concepts and syntax that were introduced in the pre-class videos, in-class discussion, or on the problem sets even if they were not covered in the videos or readings, specifically including:
-
Data and variables: integers, floating point numbers, strings, and lists
-
Arithmetic operations on numeric data
-
Sequence operations (concatenation, indexing and slicing) on strings and lists.
-
Writing functions that take parameters and return results
-
Simple decision (if/elif/else) statements
-
Printing outputs to the console.
Preparing for the quiz
-
One way to prepare is to review the videos and readings and class notes and make a summary of the key points in your own words. “Summarizing” the material in this way is a great way to ensure that you really understand the key concepts.
-
We also encourage you to do practice problems. Options include:
-
Redoing the problems from the problem sets.
The quiz problems will tend to be short rather than long or complicated). -
Additional practice problems (below)
-
-
When working on practice problems, try to write and test your answers in Spyder (or another IDE). This will be give you an experience that is similar to the one that you have during the quiz. Do not use any outside references, as these will not be available during the quiz.
-
Feel free to post questions about the material covered on the quiz on Piazza (using the
quiz1tag).
Additional practice problems
-
Write a function
is_factor(x, n)and returns the booleanTrueifxis a factor ofn(i.e., a divisor without remainder), andFalseotherwise.For example, the function call
is_factor(3, 12)would returnTrue, and the function callis_factor(3, 11)would returnFalse. -
Write a function
same_first_two(a, b)that takes two strings, and returnsTrueif the two stringsaandbshare the same first two characters, andFalseotherwise. Examples: >>> same_first_two(‘hermans’, ‘hermits’) True >>> same_first_two(‘led’, ‘zeppelin’) False -
Write a function
letter_grade(score1, score2, score3)that takes three integer quiz scores, computes their average, and returns a letter grade as a string: “A” for 90 and above, “B” for 80–89, “C” for 70–79, “D” for 60–69, and “F” below 60.Examples: letter_grade(95, 88, 91)
“A” letter_grade(72, 68, 74) “C” letter_grade(55, 60, 50) “F” -
Write a function
shipping_cost(weight, destination)where weight is a floating-point number (in pounds) and destination is either “domestic” or “international”. The base rate isweight * 2.50fordomesticshipments andweight * 5.00forinternationalones. If the weight exceeds10.0pounds, add a $15.00surcharge regardless of destination. Return the total cost as afloat.Examples: shipping_cost(5.0, “domestic”)
12.5 shipping_cost(5.0, “international”) 25.0 shipping_cost(12.0, “domestic”)
45.0 # (122.5 + 15) shipping_cost(12.0, “international”) 75.0 # (125.0 + 15)