Copyright (C) Brad Miller, David Ranum, Jeffrey Elkner, Peter Wentworth, Allen B. Downey, Chris
Meyers, and Dario Mitchell. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with Invariant Sections being Forward, Prefaces, and Contributor List, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled “GNU Free Documentation License”.

Extra Exercises

  1. Write a function called int_return that takes an integer as input and returns the same integer.

1.1 Write a function named same that takes a string as input, and simply returns that string.

1.2 Write a function called same_thing that returns the parameter, unchanged.

  1. Write a function called add that takes any number as its input and returns that sum with 2 added.

2.1 Write a function called subtract_three that takes an integer or any number as input, and returns that number minus three.

2.2 Write a function called change that takes one number as its input and returns that number, plus 7.

  1. Write a function called change that takes any string, adds “Nice to meet you!”, and returns that new string.

3.1 Write a function named intro that takes a string as input. Given the string “Becky” as input, the function should return: “Hello, my name is Becky and I love SI 106.”

3.2 Write a function called s_change that takes one string as input and returns that string, concatenated with the string “for fun.”.

  1. Write a function, accum, that takes a list of integers as input and returns the sum of those integers.
Write a function named total that takes a list of integers as input, and returns the total value of all those integers added together.

4.2 Write a function called count that takes a list of numbers as input and returns all of the elements added togther.

  1. Write a function, length, that takes in a list as the input. If the length of the list is greater than or equal to 5, return “Longer than 5”. If the length is less than 5, return “Less than 5”.

5.1 Write a function named num_test that takes a number as input. If the number is greater than 10, the function should return “Greater than 10.” If the number is less than 10, the function should return “Less than 10.” If the number is equal to 10, the function should return “Equal to 10.”

5.2 Write a function called decision that takes a string as input, and then checks the number of characters. If it has over 17 characters, return “This is a long string”, if it is shorter or has 17 characters, return “This is a short string”.

  1. You will need to write two functions for this problem. The first function, divide that takes in any number and returns that same number divided by 2. The second function called sum should take any number, divide it by 2, and add 6. It should return this new number. You should call the divide function within the sum function. Do not worry about decimals.

6.1 Write two functions, one called addit and one called mult. addit takes one number as an input and adds 5. mult takes one number as an input, and multiplies that input by whatever is returned by addit, and then returns the result.

Next Section - Introduction