Assignment: Problems with Precision
This assignment has you explore the capabilities of integer and floating point numbers in Python.
Create a loop that sets a variable to 2^N with N going from 1 to 1024 in steps of two (i.e. 1, 2, 4, 8, 16, etc). Then, create another loop that goes from -1024 to 1 (i.e. -1024, -512, -256, etc.). Print out the value of 2^N and the type of number used. Make sure you use integer values for this exercise.
Question 1: At what value do integer variables change type and what do they change to?
Create a loop that sets a variable to 2.0^N (note the addition of the ".0") with N going from 1 to 1024 in steps of two as in the previous problem. Then, create another loop that goes from -1024 to 1. Print out the value of 2^N and the type of number used. Make sure you use floating point values for this exercise.
Question 2: Increase the change of values until the values go inifinite. At what point do the floating point variables go "infinite" (if at all)?
Note: You'll need to make sure you are using a version of Python 2.X for this exercise or you will get different results than expected. Also, depending on the approach you use you may obtain somewhat different results than other students who try different approaches.
Turn In
- A script that contains the loops mentioned above with appropriate documentation.
- Add the answers to the questions above at in the file header for the script.
Notes for next year: remove the second loop in each section (i.e. only have the students do 2 loops for this assignment). Also, increase the range on N. Note that this assignment may need to change again if ArcGIS rolls to Python 3.3.