This is to help you to study the chapter(s) on functions. One approach could be as follows:
- First, write the first line of the function to provide the name and arguments.
- Second, write the body of the function with a correct return statement if appropriate.
- Finally , update your main function to call or invoke this
function.
Here are some sample
problems on functions to work from:
- Convert an upper-case letter to a lower case letter and return the lower case letter. (Hint:
Check first to be sure that it is not lower case already.)
- For any given pair of integers, print a statement that states
whether the second is a
multiple of the first.
- For any given integer, determine and return whether it is odd or even.
- For any given (small) number, print a square of asterisks with
the length of each side equal to the given number.
- Calculate and return the area of a circle, given the radius. (Be sure to use math.pi for accuracy.)
- Simulate tossing a coin.
- Randomly select and return a number from 1 - 10.
- Given a number from 1-12, return the name of the appropriate month
- Simulate selecting one card from a deck of 52 cards.
- Given 5 numbers, return the average (mean).
- Given a single word, print it backwards. (For discussion: How many ways can you do that?)
- Given a string, return the first character or the last character, depending on the user's request
Please see your instructor with any questions.