CSC 241 Lab 3



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. (Functions)

  1. Write a function double(x) that returns double the value of x. Use it in expressions to test it, e.g. double(10) + 3 should be 23.

  2. Write a function month(n) that takes as input a number n between 1 and 12 and returns the name of the season, where numbers 1 to 3 are winter, 4 to 6 spring, 7 to 9 summer and 10 to 12 fall. Hint: you can use if/elif/else or a list (harder). 

3. (Loops)

  1. Write a function composer_long() that prints the names of all composers on the list ['Rzewski', 'Ruggles', 'Carter', 'Stockhausen', 'Stravinsky'] whose names have at least 10 letters. (Start by writing a function that prints all the names on that list.)
  2. Write a function composer_S() that prints the names of all composers on the list ['Rzewski', 'Ruggles', 'Carter', 'Stockhausen', 'Stravinsky'] whose names start with 'S'.
  3. Write a function composer(lst, letter) that lists all composers on the list lst whose last name starts with the letter letter. E.g. composer(['Rzewski', 'Ruggles', 'Carter', 'Stockhausen', 'Stravinsky'], 'S') should print the same names as the function in b.

4. (Function)

  1. Write a function score(hw_lst) that takes the list hw_lst of homework scores and returns the average homework score. Hint: use sum and len.
  2. Write a function score_dl(hw_lst) that takes the list hw_lst of homework scores and returns the average homework score after dropping the lowest homework score. Hint: use min, and adjust the len() computation.

Marcus Schaefer
Last updated: April 15th, 2019.