9.17. Exercises

  1. For each word in the list verbs, add an -ing ending. Overwrite the old list so that verbs has the same words with ing at the end of each one.

  2. In XYZ University, upper level math classes are numbered 300 and up. Upper level English classes are numbered 200 and up. Upper level Psychology classes are 400 and up. Create two lists, upper and lower. Assign each course in classes to the correct list, upper or lower. HINT: remember, you can convert some strings to different types!

  3. Starting with the list myList = [76, 92.3, ‘hello’, True, 4, 76], write Python statements to do the following:

    1. Append “apple” and 76 to the list.

    2. Insert the value “cat” at position 3.

    3. Insert the value 99 at the start of the list.

    4. Find the index of “hello”.

    5. Count the number of 76s in the list.

    6. Remove the first occurrence of 76 from the list.

    7. Remove True from the list using pop and index.

    Show Comments
  4. The module keyword determines if a string is a keyword. e.g. keyword.iskeyword(s) where s is a string will return either True or False, depending on whether or not the string is a Python keyword. Import the keyword module and test to see whether each of the words in list test are keywords. Save the respective answers in a list, keyword_test.

  5. The string module provides sequences of various types of Python characters. It has an attribute called digits that produces the string ‘0123456789’. Import the module and assign this string to the variable nums. Below, we have provided a list of characters called chars. Using nums and chars, produce a list called is_num that consists of tuples. The first element of each tuple should be the character from chars, and the second element should be a Boolean that reflects whether or not it is a Python digit.

9.17.1. Contributed Exercises

You have attempted of activities on this page