Study sheet for CS199 Computer Science for Beginners
Spring 2009 – Test 1
The test will cover material from the book in Chapters 1, 2, 3 and Sections 4.1 and 4.2 in Chapter 4.
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.