find
, index
, replace
, ord
, chr
, str
, count
) and immutabilityinput
functionappend
, insert
, pop
, sort
, reverse
, index
, count
, remove
) and mutabilitykeys
, values
, items
, get
, membership, index operator, del
) anditems
)min
and max
functionsI suggest you review chapters 3 & 4 from our book, and reading quizzes 8-14. Our book, homework, and all in-class activities give you many examples that you can work through to practice.
Instructions are the same as previous exam. The exam will be conducted in-person during class over the period of two class sessions. It is closed book, no calculators, no notes. You will have the duration of class time to finish the exam. It must be completed individually.
Bring your laptop and a charger. You are responsible for ensuring your laptop is properly charged on the day of the exam. You may bring a single one-sided 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.
You will be a spare sheet of paper that has the academic integrity pledge. Print your name at the top. When you are finished with the exam, you will hand in this paper with the time the exam was submitted and show me (or a TA/ZI) on your laptop that your Moodle quiz has been submitted.
You will open Moodle in class. Moodle is the ONLY program that can be running; no other tabs in your browser, no plug-ins nor browser extensions, no Thonny, nor any other application. Moodle must be the ONLY tab open. Keep your eyes on your laptop only. Any violation of these expectations, such as if any other program or tab is opened except for Moodle, it is grounds for an immediate F on the exam.
Navigate on Moodle to “Exam 2 - Part A”. In class, I will give you the password to open the exam. Some problems are worth more points depending on their level of difficulty and number of subproblems; you can see how many points a question is worth in Moodle on the left side. Review your answers before you submit. Questions have the following form.
5
.You will be a spare sheet of paper that has the academic integrity pledge. Print your name at the top. When you are finished with the exam, you will hand in this paper and show me on your laptop that your python file has been submitted.
You will open Moodle and Thonny in class. These are the ONLY programs that can be running; no other tabs in your browser, no plug-ins nor browser extensions, no Thonny, nor any other application. Keep your eyes on your laptop only. Any violation of these expectations, such as if any other program is opened, it is grounds for an immediate F on the exam.
There are roughly ~4 programming problems to solve. It is expected that your code will not have any syntax errors, and will follow the implementation instructions. Questions will have the following form to implement a function with provided instructions, input, and expected output. For example:
reverse_words(sentence)
that takes a string containing multiple words and returns a string where the order of the words is reversed. Call the function to test it using the given input. For example,
reversed = reverse_words("Python is great for scientific computing")
print(reversed)
would output
computing scientific for great is Python
filter_even_numbers(myList)
that takes a list of integers and returns a new list containing only the numbers from myList
that were even. Call the function to test it using the given input. For example,
numbers = [1, 2, 3, 4, 5, 6]
newList = filter_even_numbers(numbers)
print("Original list:")
print(numbers)
print("Filtered list:")
print(newList)
would output
Original list:
[1, 2, 3, 4, 5, 6]
Filtered list:
[2, 4, 6]
count_consonants(myString)
that takes one string argument and returns the number of consonents (vowels are “a”, “e”, “i”, “o”, “u”; consonants are all other letters of the alphabet). Case does not matter. Call your function to test it using the input below.
print( count_consonants("Hello there!") )
print( count_consonants("hi") )
would output
6
1
word_occurrences(myString)
that takes one string argument consisting of words (only letters capital or lowercase and spaces). The function should return a dictionary in which each key represents a word from the string normalized to lowercase, and the value represents the number of times that the word appeared in the string. Call your function to test it using the input below.
s1 = "Hi You how are you"
print( word_occurrences(s1) ) # outputs {'hi': 1, 'you': 2, 'how': 1, 'are': 1}
s2 = "in the cat in the hat"
print( word_occurrences(s2) ) # outputs {'in': 2, 'the': 2, 'cat': 1, 'hat': 1}