Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # Author: Landon Mayo
- # Exercise 2.4 Assume that we execute the following assignment statements:
- # width = 17
- # height = 12.0
- '''
- For each of the following expressions, write the value of the expression and the type (of the
- value of the expression).
- '''
- # 1. width/2
- # 2. width/2.0
- # 3. height/3
- # 4. 1 + 2 * 5
- # Use the Python interpreter to check your answers.
- # 1. value=8, type=int
- '''
- >>> 17/2
- 8
- >>> type(17/2)
- <type 'int'>
- >>>
- '''
- # 2. value=8.5, type=float
- '''
- >>> 17/2.0
- 8.5
- >>> type(17/2.0)
- <type 'float'>
- >>>
- '''
- # 3. value=4.0, type=float
- '''
- >>> 12.0/3
- 4.0
- >>> type(12.0/3)
- <type 'float'>
- >>>
- '''
- # 4. value=11, type=int
- '''
- >>> 1 + 2 * 5
- 11
- >>> type( 1 + 2 * 5 )
- <type 'int'>
- >>>
- '''
Advertisement
Add Comment
Please, Sign In to add comment