Exercises

  1. Write code to create a list of integers from 0 through 52 and assign that list to the variable numbers. You should use a special Python function – do not type out the whole list yourself. HINT: You can do this in one line of code!

1.1 Write code to create a list of numbers from 0 to 67 and assign that list to the variable nums. Do not hard code the list.

  1. For each character in the string already saved in the variable str1, append each character to a list called chars.

2.1 For each character in the string saved in ael, append that character to a list that should be saved in a variable app.

  1. Assign an empty string to the variable output. Using the range function, write code to make it so that the variable output has 35 a s inside it (like "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"). Hint: use the accumulation pattern!

3.1 Create an empty string and assign it to the variable lett. Then using range, write code such that when your code is run, lett has 7 b’s ("bbbbbbb").

  1. Given the list of numbers, numbs, create a new list of those same numbers increased by 5. Save this new list to the variable newlist.

4.1 For each number in lst_nums, multiply that number by 2 and append it to a new list called larger_nums.

  1. Challenge Now do the same as in problem 4, but do not create a new list. Overwrite the list numbs so that each of the original numbers are increased by 5.
  1. For each word in the list verbs, add an -ing ending. Save this new list in a new list, ing.

6.1 Challenge Do the same as above, but do not create a new list. Instead, overwrite the old list so that verbs has the same words with ing at the end of each one.

  1. For each string in wrds, add ‘ed’ to the end of the word (to make the word past tense). Save these past tense words to a list called past_wrds.
  1. Count the number of characters in string str1. Do not use len(). Save the number in variable numbs.
  1. Create a list of numbers 0 through 40 and assign this list to the variable numbers. Then, accumulate the total of the list’s values and assign that sum to the variable sum1.
Next Section - Extra Exercises