T-Th 9:05 |
CS 1110: Introduction to Computing Using Python Fall 2012 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Main
About: Announcements Staff Consultants Times & Places Calendar Materials: Texts Python Command Shell Terminology Handouts: Lectures Assignments Labs Assessment: Grading Exams Resources: CMS Piazza (link) Piazza (about) AEWs FAQ Python API Style Guide Academic Integrity |
Python ExpressionsThere is a PDF version of these instructions, if you would prefer to have that instead. This lab serves two purposes. First, it is designed to get you started with using Python immediately — either in the lab or on your own computer. Second, gives you hands on experience with Python expressions, which we talked about on the first day of class. With that said, you are not expected to be be writing any programs for this lab; for the most part you will just be using Python as a glorified calculator. Getting Started with PythonIf your primary computer is a laptop, bring it to the lab as it is an excellent opportunity to get started with Python on your machine. Follow the instructions on the Installing Python page. Feel free to ask a consultant for help if you run into problems; that is why they are there. Even if you are just planning to use Python on the ACCEL-lab computers, you still need to learn how to use the Windows "Command Prompt" before you can get started. Even though it is not officially part of this lab, you should read the tutorial on the Command Prompt before continuing on with this lab. Once you understand how to use the Command Prompt, you can get started by typing the word python at the prompt. If you are working in the ACCEL-lab, you should see output that looks something like this:
To use Python, type your expression after the There are several shortcuts that can make working with the Python prompt a lot easier. If you press the up-arrow key, you obtain the previous expression that you typed in. Pressing up-arrow repeatedly can scroll through all the expressions that you have typed this session. And if you go too far back, you can press the down-arrow key to get to a later expression. The left and right-arrow keys moves the text cursor on a single line. Using all of these keys together, you can take a previously-used expression, modify it, and then try it again. Lab Instructions
Below is a list of expressions. For each expression, we would like you to first compute
the expression in your head, without Python. You should write down what you think the
value is in the second column of the table. If you have no idea, you should write "?".
Once you have done that, you should then use Python to compute the same expression. Simply
cut and past the expression from this webpage into the interactive shell, and hit the
If the two values are different, you should try to figure out why Python gave the answer that it did. Come up with a reasonable explanation and put it in the final column. You are not really being graded on these labs (see Turning In the Lab), so you should just make your best guess at what is happening; your answer will help the instructor and consultants understand how to better aid you. As this is the first lab, it is a little shorter than some of the future labs. With that said, do not waste time! If you don't understand something, ask your lab instructor or a consultant immediately. It is very important that you understand how each expression is evaluated, so if an answer doesn't make sense, ask someone. The lab instructors and consultants are in the lab to help. They will look over your shoulder from time to time and give you advice. Turning in the LabLabs are graded on effort, not correctness. When you are finished, you should show your written answers to this lab to your lab instructor, who will record that you did it. If you do not finish during the lab, finish it within the next few days and show it to your lab instructor next week. Because the lab is graded on effort, you should focus all of your efforts on understanding and not just getting the answers correct. The primary purpose of thes labs is for you to have a hands-on session during which the consultants and instructors can help you out. Lab ProblemsINT Expressions
FLOAT Expressions
Casting and Typing
BOOLEAN Expressions
For the last two expressions in the table above, answer the following question:
why does the last expression in the table not work but the one above it does?
String ExpressionsIn the expressions below, pay close attention to the types of quotation marks being used. We use three different types of quotation marks: ' (single quote), " (double quote), and ` (backquote, reached by hitting shift on the ~ key). In particular, we use the backquote in the last three expressions below.
Given the results in the table above, answer the following question: what is the difference
between the three different types of quotes?
Variables and Assignment StatementsSo far, you have only worked with expressions. In the table below, we have included assignment statements. It is important that you know the difference between an expression and a statement. An assignment statement like b = 3 < 5is a command to do something; it evaluates the expression 3 < 5
and stores its value in variable b. Because it is not an expression, Python will not
actually output a result when you type it in. It will just perform the command
silently.
As with the previous part of this lab, you should complete the table below. However, you must enter the expressions or statements in the table below in exactly the order that they are given. Otherwise, you may get different results from everyone else. If the table row is a statement, Python will not return a value, so enter "None" for the value. We have already done this for one of the entries below.
|