Program Development
There are several full length programs in the book. I would like
you to copy these pieces of code and get them to run. Your code must
have the following template:
# File:
# Description:
# Name:
# Date:
def main():
# the body of the program
...
main()
Each program will be in a file by itself with .py extension. You
must make sure that it runs as shown in the book.
- Listing 2.1: ComputeArea.py
- Listing 2.2: ComputeAreaWithConsoleInput.py
- Listing 2.3: ComputeAverage.py
- Listing 2.4: ComputeAverageWithSimultaneousAssignment.py
- Listing 2.5: DisplayTime.py
- Listing 2.6: SalesTax.py
- Listing 2.7: ShowCurrentTime.py
- Listing 2.8: ComputeLoan.py
- Listing 2.9: ComputeDistance.py
After you have made sure all the programs run on the command line,
zip all the files together into a single file called:
myuteid_chap_2.zip
Substitute your UT EID for the place holder myuteid in the file
name. Upload the zip file to the turnin
system. Do not upload the files individually. We must
receive the zip file by 11 PM on Wednesday, 26 June 2013.
Number Conversions
These are exercises that you do. You do not have to turn these in.
- Convert the following numbers in decimal to 8-bit 2's complement
binary: 28, -39
- Write the binary equivalent of all numbers from 0 to 15 in 4-bit
binary.
- These are 8-bit 2's complement binary. What decimal numbers do
they represent?
- 0110 1100
- 1111 1111
- 1000 0000
- 0111 1111
- Convert the following numbers to unsigned binary, octal,
and hexadecimal: 25, 32, 67, 96.
- Convert these numbers in octal to binary, decimal, and
hexadecimal: 672, 215.
- Convert these hexadecimal numbers into binary, octal, and
decimal: 2A5, D0C.
- The hexadecimal number B4 is a 2's complement number in 8-bit
binary. Convert it to decimal.
- Add 3D and F5 and express the answer in octal.
- Add 517 in octal to 3A in hexadecimal and express the answer
in decimal. [Hint convert both numbers to binary and add.]
- Add the following 2's complement 8-bit numbers: 1011 1001 and
1110 0110. Ignore the overflow bit. Express the answer in decimal.