{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"math.9x9.py.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python2","display_name":"Python 2"}},"cells":[{"cell_type":"markdown","metadata":{"id":"YwSeDRUc0DKE","colab_type":"text"},"source":["Prototype: Using two loops to enumerate the 9x9 multiplication table items."]},{"cell_type":"code","metadata":{"id":"rCKjRAq7zthR","colab_type":"code","colab":{}},"source":["#\n","# Function:\n","#\t- Create a 9x9 multiplication table\n","#\n","for n1 in [1, 2, 3, 4, 5, 6, 7, 8, 9]:\n","\tprint '-' * 12 # boundary line\n","\tfor n2 in [1, 2, 3, 4, 5, 6, 7, 8, 9]:\n","\t\tprint (\"%d x %d = %2d\" % (n1, n2, n1*n2))\n","print '=' * 12 # end of table"],"execution_count":0,"outputs":[]},{"cell_type":"code","metadata":{"id":"x_zA6yYqxyIJ","colab_type":"code","colab":{}},"source":["#\n","# Function:\n","#\t- Create a 9x9 multiplication table\n","#\n","# Skills:\n","#\t- for-loop x 2\n","#\t- list\n","#\t- range() starting from non-zero\n","#\t- string repeation\n","#\t- string formatting\n","#\t- Python2/Python3 print\n","#\n","numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]\n","for n1 in numbers:\n","\tprint '-' * 12\n","\tfor n2 in range(1,10):\n","\t\tprint \"%d x %d = %2d\" % (n1, n2, n1*n2)\n","print '=' * 12"],"execution_count":0,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"pqOte8Hzybge","colab_type":"text"},"source":["* n1, n2 - Swap the use of range() and list of numbers []"]},{"cell_type":"code","metadata":{"id":"l8EBHShqyj6U","colab_type":"code","colab":{}},"source":["for n1 in range(1,10):\n","\tprint '-' * 12\n","\tfor n2 in numbers:\n","\t\tprint (\"%d x %d = %2d\" % (n1, n2, n1*n2))\n","print '=' * 12"],"execution_count":0,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"-hoxhmcJ9pkJ","colab_type":"text"},"source":["Challenge: (any or combination of the following changes)\n","\n","\n","1. Write 9x9x9 Table\n","2. Output Horizontally\n","3. Output in matrix form (matrix[i][j] = i*j)\n","\n","\n","\n"]}]}