9.12. Exercises

  1. Write a program that will print out the length of each item in the list as well as the first and last characters of the item.

  2. Write code to determine how many t’s are in the following sentences.

  3. Although Python provides us with many list methods, it is good practice and very instructive to think about how they are implemented. Implement a Python function that works like the following:

    1. count

    2. in

    3. reverse

    4. index

    5. insert

    Show Comments
  4. Write a Python function that will take a list of 100 random integers between 0 and 1000 and return the maximum value. (Note: there is a builtin function named max but pretend you cannot use it.)

    Show Comments
  5. Write a function sum_of_squares(xs) that computes the sum of the squares of the numbers in the list xs. For example, sum_of_squares([2, 3, 4]) should return 4+9+16 which is 29:

  6. Write a function to count how many odd numbers are in a list.

    Show Comments
  7. Sum up all the even numbers in a list.

  8. Sum up all the negative numbers in a list.

    Show Comments
You have attempted of activities on this page