Exercises¶
- 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.
- For each character in the string already saved in the variable
str1, append each character to a list calledchars.
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.
- Assign an empty string to the variable
output. Using therangefunction, write code to make it so that the variableoutputhas 35as 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").
- Given the list of numbers,
numbs, create a new list of those same numbers increased by 5. Save this new list to the variablenewlist.
4.1 For each number in lst_nums, multiply that number by 2 and append it to a new list called larger_nums.
- Challenge Now do the same as in problem 4, but do not create a new list. Overwrite the list
numbsso that each of the original numbers are increased by 5.
- 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.
- 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 calledpast_wrds.
- Count the number of characters in string
str1. Do not uselen(). Save the number in variablenumbs.
- 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 variablesum1.