Assignment 1
Interactive Python and Scripting
Submit before 11:30 PM Friday September 15
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 file called assn1.txt that contains the following:
- A statement (a paragraph or more) that summarizes your completion of the assignment. It should include who you collaborated with (if anyone) and any online resources that you used.
- 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.txt file)
- Running examples that demonstrate that your script works correctly (copy the text that shows your py file running and paste it in the assn1.txt file)
Submit your assn1.txt file to D2L.