# Chapter 7 Exercises¶

1. Complete lines 1 and 2 below to create the code to add up all the numbers from 1 to 5 and print the sum.

2. Fix the errors in the code so that it prints the sum of all the numbers 1 to 10.

3. Change the code below into a function that returns the sum of a list of numbers. Pass the list of numbers as a parameter and print the result of calling the function.

4. Fix the errors in the code so that it prints the product of every 5th number between 5 and 25, inclusive. So, the product of 5, 10, 15, …, 25.

5. Fill in the missing code on lines 3 and 4 to loop through the list of numbers and calculate the product. Add a line at the end to print the value in product.

6. Fix the errors in the code so that it prints the sum of all the odd numbers 1 through 20.

7. Modify the code below to create a function that calculates the product of a list of numbers and returns it. Have the function take a list of numbers as a parameter. Call the function to test it and print the result of calling the function.

8. Fix the error in the code so that it takes each string in the list and prints out the sentence “I like to eat pizza”.

9. Fill in the code below on lines 2, 4, and 6 to correctly add up and print the sum of all the even numbers from 0 to 10 (inclusive).

10. Write code that prints the square of each number 1 through 10 in the format “1 * 1 = 1”, etc.

11. Define a function to calculate the sum of the even numbers from 0 to the passed number. Return the sum from the function. Call the function and print the result.

12. Create a function that returns the factorial of a passed number and call the function and print the result.

13. Fix the code below to correctly calculate and return the product of all of the even numbers from 10 to 20.

14. Create a list of all odd numbers from 1 to 20 and find the average. Then create a list of numbers from 1 to 100 using the average as the increment and print the product of those numbers.

15. Create a procedure to calculate and return the sum of all of the odd numbers from 1 to a passed last number (inclusive). Call the function to test and it print the result.

16. Complete the code for a function that takes a list of letters and combines them into a word. It should print “Hi”.

19. Write a function that will take a list of numbers and return the average. Remember that the average is the sum of all of the numbers in the list divided by the number of items in the list. You can get the length of a list using the len(list) function.