Homework Assignment Number 2
- Read chapter 2 in Donaldson book
- Open an Idle shell and do exercises listed below
- There are 2 types of information requested:
- If an exercise involves writing code, write code that solves that problem and run it.
- If a question requires an explanation, write that
explanation as a comment (preceded by #)
- When you are done, save the contents of the IDLE window (see File menu).
- Name this file: Homework2-your-name.txt
- Submit the resulting file using Blackboard.
- Important: this is the First and Last time that we will be handing in Idle Output (saved as a .txt file) In the future, we will start writing program files (scripts) and saving them as .py files.
Exercises:
- Use the print function to print the following strings, including
the embedded quotes and blank lines:
- The newscaster said, “And Now for Something Completely
Different!”
- One quote: ', Two quotes “, Red Quotes,
Blue Quotes
- Evaluate the following expressions and explain (as comments) why they yield different answers:
- '5' + '4'
- 5 + 4
- Incorporate type conversion into a statement so that you combine
'5' and '4' to get '9'
- Evaluate each of the following expressions. Then make a new
version of each expression incorporating parentheses that
make the order of operations explicit. Evaluate this second
expression (you should get the same result).
– Example: 1*1**1+1 and (1*(1**1))+1 both evaluate as 2
- 5*5/5–5
- 5-5**5*5
- 60-40*1.5+5**2-25
- Evaluate the following expressions:
- 3%3, 4%3, 7%3, 25%3, 98%3, 137%3, 1997%3, 1313%3
and 10011%3
- Make lists (as a comment) of 3 sets: the set of numbers
such that X%3 = 0, the set where X%3 = 1 and the set
where X%3 = 2
- Only list numbers from part A. Otherwise the sets would be infinite.