Assignment 2
Interactive Python and Scripting
Submit before 11:30 PM Saturday April 13
Overview
You will continue to work with the Python interactive shell and the Integrated Development and Learning Environment (IDLE). As before, make sure you copy and paste your work in a text editor to ensure that your work is saved.
Interactive Python
Using the interactive Python shell, type in and evaluate Python expressions for each of the following. Use online resources if you are not sure of the needed Python operator for performing an operation.
- Try out the following expressions and statements:
- 10 / 3
- 10 // 3
- 10 % 3
- list1 = ["cat", "dog", "emu"]
- list2 = ["asp", "bat", "owl"]
- len(list1)
- list1 + list2
- list3 = [23, 45, 10]
- sum(list3)
- Assign these hiking distances to a list: 12, 23, and 18 miles. Then, using your list, find the average distance.
Python Questions
- Explain the difference between these three operators: /, //, %.
- Assign 8 to the variable
val
. What happens if you type in"The answer is " + val
? What do you need to do to avoid the error? - What is the difference between
int("10")
andfloat("10")
?
Python Scripts (little programs)
Write and test Python scripts (create a py file each) that do the following:
- Read in three integers (use input statements) and write out a summary message that includes the average of the three integers.
- Prompts and reads (use input statements) in three words or phrases (e.g. a color, an action, an animal) and then produces a short statement or story that includes the three words or phrases.
Deliverables
Create a text or pdf file called assn2.txt or assn2.pdf that contains the following:
- A statement that summarizes your completion of the assignment. Discuss your experience. Note any help or collaboration.
- The text of your interactive Python exercises
- The answers to the questions
- For each of your Python scripts:
- A listing of the script (copy the code in the py file and past it in the assn1 file)
- Running examples that demonstrate that your script works correctly (copy the text that shows your py file running and paste it in the assn2 file)
Submit your assn2 file to D2L.