diff options
author | hardythe1 | 2015-07-03 12:23:43 +0530 |
---|---|---|
committer | hardythe1 | 2015-07-03 12:23:43 +0530 |
commit | 5a86a20b9de487553d4ef88719fb0fd76a5dd6a7 (patch) | |
tree | db67ac5738a18b921d9a8cf6e86f402703f30bdf /C_Programming:_A_Modern_Approach_by_K.N._King/Chapter7.ipynb | |
parent | 37d315828bbfc0f5cabee669d2b9dd8cd17b5154 (diff) | |
download | Python-Textbook-Companions-5a86a20b9de487553d4ef88719fb0fd76a5dd6a7.tar.gz Python-Textbook-Companions-5a86a20b9de487553d4ef88719fb0fd76a5dd6a7.tar.bz2 Python-Textbook-Companions-5a86a20b9de487553d4ef88719fb0fd76a5dd6a7.zip |
add/remove books
Diffstat (limited to 'C_Programming:_A_Modern_Approach_by_K.N._King/Chapter7.ipynb')
-rwxr-xr-x | C_Programming:_A_Modern_Approach_by_K.N._King/Chapter7.ipynb | 154 |
1 files changed, 154 insertions, 0 deletions
diff --git a/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter7.ipynb b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter7.ipynb new file mode 100755 index 00000000..dde0a9b8 --- /dev/null +++ b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter7.ipynb @@ -0,0 +1,154 @@ +{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:f68b9bfb9c3fa936de40e570b5ee8d7a82f02160fce8cc4fc8384697c0b86ac7"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 7: Basic Types"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example sum2.c, Page 131"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def main():\n",
+ " sum=0\n",
+ " print \"This program sums a series of integers.\"\n",
+ " n=int(raw_input(\"Enter integers (0 to terminate): \")) #input the integers to operate on\n",
+ " while(n!=0):\n",
+ " sum=sum+n #calculating sum till 0 encountered\n",
+ " n=input()\n",
+ " print \"The sum is: %d\" % sum #printing sum\n",
+ "if __name__=='__main__':\n",
+ " main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "This program sums a series of integers.\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter integers (0 to terminate): 8\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "23\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "71\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The sum is: 107\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example length.c, Page 142"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def main():\n",
+ " str=raw_input(\"Enter a message: \") #input string\n",
+ " length=len(str) #calculate length\n",
+ " print \"Your message was %d character(s) long\" % length #display length\n",
+ "if __name__=='__main__':\n",
+ " main()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a message: Brevity is the soul of wit.\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Your message was 27 character(s) long\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+}
\ No newline at end of file |