Submission: Submit the python or text file that contains all your answers to the submission folder for this lab by the end of the lab. To simplify Drew's (our tutor) work, please include your name and the number of the lab at the top of the file (if you're submitting a Python file, use comments: start the line with a #).
Grading: see the grading criteria for lab assignments.
1. (From printing to accumulation) Our goal is to write a function cons(s) which removes all vowels ('aeiou') from a string s and returns a string just consisting of the consonants in s. We'll do this in two steps. Note: replace, remove, etc. are not allowed.
a) Write a function cons_prt(s) which prints the consonants in s, one at a time.
b) Write a function cons(s) which returns a string containing the consonants in s. Hint: instead of printing, accumulate. Don't forget to initalize your accumulation string, and to return it.
2. (Loops and Lists and Strings)
Write a function uppercase(s) which counts how many
letters in the string s are upper case and returns that value.
Hint: loop and counter variable. You'll find the .isupper() method useful.
Write a function positive(lst) which as input takes a
list, and as output returns a list which only contains the positive
elements of lst. For example,
Hint: Write a loop. First, print only the positive numbers. Then accumulate them in a list (you need a second list variable). The last test case tells you how to initialize the second variable.
3. (Strings and list) Another linguistic experiment. You are trying to test whether short words matter in English, so you want to write a function long(s) which keeps only the words of length greater than 3 in s. Hint: you can start with one of the title(s) examples we did in class (or at least looking at them will be instructive). Work with split() and join().
4. (Extra Credit, 3pt)
The Roman numeral MDCXVII corresponds to 1617: M = 1000, D = 500, C = 100, X = 10, V = 5, I = 1. There are more complicated rules, e.g. IV usually is 4, but we'll use a simple version of Roman numerals where we just accumulate the values of all symbols. E.g. MIIIMMDCM we'll evaluate as 4*1000 + 3*1 + 1*500 + 1*100 = 4603. Write a function roman(s) that takes as an input a string s and returns the decimal value of s as a Roman numeral according to these simplified rules. Hint: work with count().