CSCI-UA.2 - Introduction to Programming (Python) - Department of Computer Science, New York University


Class Review Exercises on Functions

This is to help you to study the chapter(s) on functions. One approach could be as follows:

  1. First, write the first line of the function to provide the name and arguments.
  2. Second, write the body of the function with a correct return statement if appropriate.
  3. Finally , update your main function to call or invoke this function.
Here are some sample problems on functions to work from: 
  1. 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.)
  2. For any given pair of integers, print a statement that states whether the second is a multiple of the first.
  3. For any given integer, determine and return whether it is odd or even.
  4. For any given (small) number, print a square of asterisks with the length of each side equal to the given number.
  5. Calculate and return the area of a circle, given the radius. (Be sure to use math.pi for accuracy.)
  6. Simulate tossing a coin.
  7. Randomly select and return a number from 1 - 10.
  8. Given a number from 1-12, return the name of the appropriate month
  9. Simulate selecting one card from a deck of 52 cards.
  10. Given 5 numbers, return the average (mean).
  11. Given a single word, print it backwards. (For discussion: How many ways can you do that?)
  12. Given a string, return the first character or the last character, depending on the user's request

Please see your instructor with any questions.