Activity 27 - What else? 🤔
The exam approaches. What else would you like to have practice with? What thing in python do you struggle with the most? Pick one or more options below. We can do any of these together in class. You can also pick ANY of the previous in-class activities.
Create a file exam2-practice.py
and save to your cs100/ch5
folder.
Option A: Manipulating strings
- Use the repetition operator to print out “cool.” 7 times
- Break up a sentence into a list of words
- Find the number of occurences of the word ‘the’ in a given string.
- Use substring operator to print “awesome” from “CS100 is super awesome”.
- Use index operator to print “i” from the same string.
Option B: Encryption/decryption
- Use a substitution cipher to encode & decode a string (see activity 15)
- Use a transpotition cipher to encode & decode a string (see activity 15)
- Use a caesar cipher to encode & decode a string (see activity 16)
Option C: Lists
- Use a for loop to create a list
listA
that contains 10 random numbers.
- Use a list comprehension to create a list
listB
that contains 10 random numbers
- Print “found it” if
1
is in the list
- Print the list sorted in ascending order.
- Use a while loop to add values input from the user into a list.
Option D: Dictionaries
- See activity 20 (dictionaries)
- Create a dictionary containing the name and value of US denominations (penny, nickel, etc.)
- Write a function that merges two dictionaries
- Add a value to a dictionary
- Use a while loop to add (key, value) pairs input from the user into a dictionary.
- See activity 21 (Frequency distribution)
- See activity 23 (Correlation)
- Consider the list
a=[1, 2, 3, 4, 1, 2, 3, 1, 3, 1, 2, 4, 5, 1, 2, 3, 6, 7, 3, 3, 1]
. Compute the mean, median, mode, and calculate the frequency distribution.
Option F: Reading/writing to files
- See activity 23
- Save the rainfall.txt file locally. Count how many lines are in the file.
- Create a file called
numbers.txt
and write to it the first 100 numbers using a while loop
Option G: Reading from internet
- Read (but do not download) the file from
http://csweb.wooster.edu/hguarnera/cs100/assignments/rainfall.txt
. Output the contents of the page to the terminal decoded in UTF-8 format.
Option Z: Nothing is hard.
Cool beans. Pick 5 questions from above and complete them independently.
How to submit
Save your work in a file called exam2-practice.py
and submit to Moodle.