{ "metadata": { "name": "", "signature": "sha256:8846db95d13f18ddbaba03cb28aa141be8268e397ec14735e02a0f66209b0b25" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "Chapter 16: Floating point" ] }, { "cell_type": "heading", "level": 3, "metadata": {}, "source": [ "Example 16.1, Page number: 322" ] }, { "cell_type": "code", "collapsed": false, "input": [ "\n", "# Variable declaration\n", "number1 = 1.0\n", "number2 = 1.0\n", "counter = 0\n", "\n", "# Calculation and result\n", "while (number1 + number2 != number1) :\n", " counter += 1\n", " number2 = number2 / 10.0\n", "\n", "print ('%2d digits accuracy in calculations\\n' % counter)\n", "\n", "\n", "number2 = 1.0\n", "counter = 0\n", "\n", "result = number1 + number2\n", "counter += 1\n", "number2 = number2 / 10.0\n", "\n", "print ('%2d digits accuracy in storage\\n' % counter)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "16 digits accuracy in calculations\n", "\n", " 1 digits accuracy in storage\n", "\n" ] } ], "prompt_number": 1 } ], "metadata": {} } ] }