CS 1110 - Introduction to Programming

Review for Second Test

The following questions are provided to help you study for the second test. Do not expect to see these exact questions on the test.

  1. In Python, what is a function?

  2. How do functions allow your programs to be more modular?

  3. When we pass a value to a function, what do we call that value? How do we actually pass it?

  4. What is a function definition? When does a function definition require that you put something inside its set of parentheses?

  5. How does a hierarchy chart require functions to be arranged?

  6. What is the scope of a variable? How does it affect commands that use that variable?

  7. What are the two types of variables that are based on their scope?

  8. How do you make a local variable? How do you make a global variable? How do you use it in a function?

  9. What is a parameter variable?

  10. What is a void function? What do you have to do to make one?

  11. How are constants implemented in Python?

  12. What is the import command used for in Python? How did you need to use it to generate random numbers?

  13. How should we write a line of code that calls a function stored in a library module?

  14. What is the secret to creating a function that returns a value?

  15. If a function returns two values, how should we write a line of code to receive them?

  16. When we ask a user to input a number, why might we want to cast it as an integer?

  17. Explain how to use the modulus operator to determine whether a number is even or odd.

  18. What function is used to create a file object in a Python program?

  19. What are the six modes that we discussed that can be used when opening a file?

  20. Name and explain some of the methods that are associated with file objects.

  21. In general, how can we tell when we have reached the end of a file we are reading?

  22. Why might you want to use a file object's name as the iterative in a for-in loop?

  23. What is an exception? What can we do in a program if we expect that one might happen?

  24. What is the basic structure of an exception handler?

  25. What is the purpose of a finally: suite?

  26. What is a sequence? What have we learned about in this class that would qualify as sequences?

  27. What notation is used to create and populate a list?

  28. How might we use the repetition operator to create a list of 12 zeros?

  29. Write a line of code that uses the range() function and the list() function to create a list of values running from 1 to 500.

  30. Write a loop to print each element in the list you created in the question above.

  31. Write a line of code that assigns a new value to the fifth element in the list that was created in problem 29 above. Assign the value 2017.

  32. What is the difference between using the del command and using the remove() method of a list?

  33. What does the index() method of a list take as an argument? What does it return?

  34. What would happen if you had a line of code that said list1 = list2?

  35. What is a file object? What does the writelines() method of a file object expect as an argument?

  36. What is the difference between a list and a tuple?