Study sheet for CS199 Computer Science for Beginners

 

Spring 2009 – Test 3

 

The test will cover material from the entire class. 

 

Part of this test will be closed book.  You will be asked to write small Python programs that have an infinite while loop and that have infinite recursion.  You may also be asked to write small Python programs that use recursion or while loops that do NOT have an infinite loop or that do NOT have infinite recursion.

 

The remainder of this test will be an open book test.  This means that you should bring your textbook so that you can refer to it during the class.  You may NOT use any notes or any other books.  You may NOT use a calculator or a computer.

 

This first list of topics is repeated from the study sheet from Test 1.  Note, for this test, the expressions, for example, may be more complex.

 

For test 1 (but also for test 2) you should be able to:

 

·         Recognize Python data types of: int, long, float, str, and bool.

·         Recognize and evaluate syntactically well-formed Python expressions that involve constants and variables with the standard operators.  The constants and variables can be of the following types: int, long, float, str, or bool.   This means that you need to understand how the mathematical operators behave based on the input.  For example, you need to know how x+y will behave: when x and y are both of type int; when x is of type int and y is of type float; when x and y are both of type str, etc.

·         Explain how a value of type long is different from a value of type int.

·         Recognize syntactically invalid Python expressions and be able to explain why they are syntactically invalid

·         Recognize whether or not two Python expressions evaluate to the same value.

·         Use the Python print statement to print out text strings, constants, and variables.

·         Use the Python input statement to get one or more than one input from the user.

·         Use the Python raw_input statement to get a text string as input from the user.

·         Define a function in Python that does not return a value.

·         Define a function in Python that returns one value.

·         Define a function in Python that returns more than one value.

·         Recognize and evaluate a syntactically correct Python assignment statement.

·         Recognize and evaluate a syntactically correct multiple assignment statement, where several variables receive several values, at the same time based on the one statement.

·         Recognize and evaluate a syntactically correct if statement.

·         Recognize and evaluate a syntactically correct else statement.

·         Recognize and evaluate a syntactically correct elif statement.

·         Recognize and evaluate a syntactically correct “for i in range()” statement.  You should understand variations on the range statement including, for example: range(10), range(3,5), range (2, 17, 2).

·         Be able to inspect individual characters in a character string.  So, for example, given a text string, you should be able to print out the characters in the even-numbered positions.  That is, print out the 2nd character, the 4th character, the 6th character, for example.

·         Be able to import the math  library and use one or more of the math library functions or constants, such as math.round() or math.pi.

·         Convert a number in base 2 to a number in base 10.

·         Convert a number in base 8 to a number in base 10.

·         Write simple programs that use any of the Python statements listed above.

·         Explain the difference between: printing a value and returning a value from a function.

·         Explain the difference between: evaluating a Python expression and executing a Python statement.

 

For test 2 (but also for test 3), you should be able to:

·         Use string formatting to print numeric values of various types as part of a Python program.

·         Open a file, read a file (line by line), and close a file in a Python program.

·         Use the operations shown on page 341 of our textbook on lists.

·         Use the methods shown on Page 353 of our textbook on list.

·         Use the operations and methods on page 341 and 343 in our textbook on tuples

·         Create and manipulate lists and tuples, including lists that contain other lists; lists that contain tuples; tuples that contains lists; tuples that contain tuples, and so forth as well as lists and tuples that contain various kinds of numbers, strings, and Boolean values.

·         Use multiple if, elif, and else statements in a single Python program, including nested if statements.

·         Use indefinite (while) loops and definite (for) loops, including nested loops, in a Python program.

·         Use if, elif, else, while, and for statements nested in various ways.

·         Use break and continue statements in while and for loops.

·         Write Python programs that use any of the data types, data structures, expressions, and statements listed in this study guide.

For test 3, you should be able to:

·         Use the random module in Python.

·         Use multiple, including nested, while loops and for loops in a single program.

·         Use multiple, including nested, while loop and for loops with if statements (and elif and else statements).

·         Compare while loops and for loops.

·         Recognize when a while loop is an infinite while loop.

·         Write and understand recursive functions in Python.

·         Recognize when a recursive function will be invoked infinitely (i.e., when is has infinite recursion).

·         Understand when it is better to use looping rather than using recursion.

·         Write and read structure charts, as described in Chapter 9 of our textbook.

·         Compare two structure charts for the same problem.

·         Define and use nested lists (or nested tuple or nested tuple/list) structures in Python, using multiple subscripts.