Chapter 2 Lab

In this lab, you will start programming in python. Before beginning this assignment, you should get comfortable with TextWrangler (or whatever text editor you are going to use) and the Python interpreter. Read over Chapter 2. Also, be comfortable using the Python launcher to run a script or program. Answer the questions below in one big file that your TA Marc can run as a Python script/program by using the Python launcher. You can use the print command to make the output look sensible for Marc. Name the file yourlastname.py. Email your completed assignment (i.e., attach your script file) from your preferred class email address to marctomlinson@mail.utexas.edu.

1a. Evaluate the following expressions:

2*3+4-2

1b. Add parenthesis to make the expression evaluate to 12.
1c. Add parenthesis to make the expression evaluate to 10.

2. The function raw_input() takes keyboard input and returns a string. For example, x=raw_input() followed by typing HELLO and hitting the return key stores the string "HELLO" in the variable x.

2a. Write a program that takes two strings entered by the user and prints both strings combined together (hint use +).
2b. Write a program that takes one string entered by the user and prints it out five times (hint, use *)

3. Python contain types string, integer, and float. The function str(), int(), and float() can be used to convert between types. Use these functions, along with raw_input(), to make a program in which the user types in an integer, then add 5 to it and print out the answer.

4. Write a program in which the user types in a temperature in celsius and the answer is printed out in fahrenheit.

5. Write a program in which the user types in a temperature in fahrenheit and the answer is printed out in celsius.

6. Can you think of a property that addition and multiplication have that string concatenation and repetition do not (page 17 bottom)?