menu COMPSCI 2120/9642/DIGIHUM 2220 1.0 documentation

Problem Set 6

Problem 6.1

Write a function even_print(ls) that takes a list of integers ls as its argument and prints out only the even elements of the list.

Problem 6.2

Write a single line of Python code to test if a particular value appears in a list (e.g. test if 5 appears in [1,7,5,3].)

Problem 6.3

Generate the following lists, using range:
  1. All integers from 0 to 17

  2. All integers from -10 to 0

  3. All integers from 10 to 0 (that is: counting down instead of up)

  4. All even integers from 0 to 20

Problem 6.4

Write a function beer_on_wall that will print out “n bottles of beer on the wall” for all n from 99 down to 1 (you must use a list). Hint: you can use range and a for loop