# Chapter 7 Exercises¶

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

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

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.

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.

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`

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

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.

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”.

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).

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

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.

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

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

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.

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.

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

Create a function to calculate and return the product of all of the even numbers from 2 to the passed end number (inclusive). Be sure to call the function to test it and print the result.

Write a function that takes two inputs, a start and stop for a range (inclusive). Find the product and the sum of all the numbers and return the average between those two numbers. make a call to the function where you print the result

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.Create a function that takes one integer parameter and gets a list of all the odd numbers in that range and all the even numbers in that range. Find the product of all the even numbers, the sum of all the odd numbers, and then return the difference of the product by the sum and divide by the average of the two. Call the function and print the result.