summaryrefslogtreecommitdiff
path: root/A_First_course_in_Programming_with_C/Chapter12.ipynb
diff options
context:
space:
mode:
authorhardythe12015-06-03 15:27:17 +0530
committerhardythe12015-06-03 15:27:17 +0530
commit47d7279a724246ef7aa0f5359cf417992ed04449 (patch)
treec613e5e4813d846d24d67f46507a6a69d1a42d87 /A_First_course_in_Programming_with_C/Chapter12.ipynb
parent435840cef00c596d9e608f9eb2d96f522ea8505a (diff)
downloadPython-Textbook-Companions-47d7279a724246ef7aa0f5359cf417992ed04449.tar.gz
Python-Textbook-Companions-47d7279a724246ef7aa0f5359cf417992ed04449.tar.bz2
Python-Textbook-Companions-47d7279a724246ef7aa0f5359cf417992ed04449.zip
add books
Diffstat (limited to 'A_First_course_in_Programming_with_C/Chapter12.ipynb')
-rwxr-xr-xA_First_course_in_Programming_with_C/Chapter12.ipynb1236
1 files changed, 1236 insertions, 0 deletions
diff --git a/A_First_course_in_Programming_with_C/Chapter12.ipynb b/A_First_course_in_Programming_with_C/Chapter12.ipynb
new file mode 100755
index 00000000..1f9a4a84
--- /dev/null
+++ b/A_First_course_in_Programming_with_C/Chapter12.ipynb
@@ -0,0 +1,1236 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 12: Files"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1, Page Number : FLS-7"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "fp = open(\"SAMPLE.TXT\",\"w\")\n",
+ "\n",
+ "print \"\\nType the text press enter key at end.\\n\\n\"\n",
+ "\n",
+ "ch = raw_input(\"\")\n",
+ "fp.write(ch)\n",
+ "\n",
+ "fp.close()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Type the text press enter key at end.\n",
+ "\n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Computer Programming in C language is widely used for Science and Engineering applications.\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2, Page Number : FLS-8"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "count = 0 \n",
+ "\n",
+ "fp = open(\"SAMPLE.TXT\",\"r\")\n",
+ "\n",
+ "print \"\\nThe content of the text file is : \\n\\n\"\n",
+ "\n",
+ "ch = fp.read()\n",
+ "\n",
+ "for i in ch:\n",
+ " sys.stdout.write(\"%c\"%(i))\n",
+ " if i.upper() == 'A' or i.upper() == 'E' or i.upper() == 'I' or i.upper() == 'O' or i.upper() == 'U':\n",
+ " count = count + 1\n",
+ " \n",
+ "print \"\\nNumber of vowels present = \",count\n",
+ "fp.close()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "The content of the text file is : \n",
+ "\n",
+ "\n",
+ "Computer Programming in C language is widely used for Science and Engineering applications.\n",
+ "Number of vowels present = 31\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3, Page Number : FLS-10"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "fp = open(\"STUDENT.DAT\",\"w\")\n",
+ "\n",
+ "n = int(raw_input(\"\\nHow many students ? \"))\n",
+ "\n",
+ "for i in range(0,n):\n",
+ " rno = int(raw_input(\"\\nStudent roll no., name, total ? \"))\n",
+ " sname = raw_input(\"\")\n",
+ " tot = int(raw_input(\"\"))\n",
+ " fp.write(\"%d %s %d\\n\"%(rno,sname,tot))\n",
+ " \n",
+ "fp.close()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "How many students ? 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Student roll no., name, total ? 101\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "ARUN\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "78\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Student roll no., name, total ? 102\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "DEEPAK\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "72\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Student roll no., name, total ? 103\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "SUSHMITHA\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "86\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4, Page Number : FLS-11"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "fptr = open(\"STUDENT.DAT\",\"r\")\n",
+ "\n",
+ "print \"\\n--------------------------------------------------------\"\n",
+ "print \"\\n Roll No Name Total \"\n",
+ "print \"\\n--------------------------------------------------------\"\n",
+ "\n",
+ "rno = 0\n",
+ "sname = ''\n",
+ "tot = 0\n",
+ "\n",
+ "lines = fptr.readlines()\n",
+ "\n",
+ "for line in lines:\n",
+ " rno,sname,tot = line.split(' ')\n",
+ " tot = int(tot)\n",
+ " if tot >= 75:\n",
+ " print \"\\n \",rno,\"\\t\",sname,\"\\t\\t\",tot\n",
+ " \n",
+ "print \"\\n--------------------------------------------------------\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "--------------------------------------------------------\n",
+ "\n",
+ " Roll No Name Total \n",
+ "\n",
+ "--------------------------------------------------------\n",
+ "\n",
+ " 101 \tARUN \t\t78\n",
+ "\n",
+ " 103 \tSUSHMITHA \t\t86\n",
+ "\n",
+ "--------------------------------------------------------\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5, Page Number : FLS-12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "ch = 'y'\n",
+ "\n",
+ "fp = open(\"STUDENT.DAT\",\"a\")\n",
+ "\n",
+ "while ch.upper() == 'Y':\n",
+ " rno = int(raw_input(\"\\nStudent roll no., name, total ? \"))\n",
+ " sname = raw_input(\"\")\n",
+ " tot = int(raw_input(\"\"))\n",
+ " fp.write(\"%d %s %d\\n\"%(rno,sname,tot))\n",
+ " print \"\\nPress y - to add more records\"\n",
+ " print \"\\n any other key to stop.\"\n",
+ " ch = raw_input(\"\")\n",
+ " \n",
+ "print \"\\n-------------------------------------------------------\"\n",
+ "print \"\\n Roll No. Name Total\"\n",
+ "print \"\\n-------------------------------------------------------\"\n",
+ "\n",
+ "rno = 0\n",
+ "sname = ''\n",
+ "tot = 0\n",
+ "\n",
+ "fp.close()\n",
+ "fp = open(\"STUDENT.DAT\",\"r\")\n",
+ "\n",
+ "lines = fp.readlines()\n",
+ "\n",
+ "for line in lines:\n",
+ " rno,sname,tot = line.split(' ')\n",
+ " print \"\\n \",rno,\"\\t\\t\",sname,\"\\t\\t\",tot\n",
+ " \n",
+ "print \"\\n--------------------------------------------------------\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Student roll no., name, total ? 104\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "RAHUL\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "67\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press y - to add more records\n",
+ "\n",
+ " any other key to stop.\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "N\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "-------------------------------------------------------\n",
+ "\n",
+ " Roll No. Name Total\n",
+ "\n",
+ "-------------------------------------------------------\n",
+ "\n",
+ " 101 \t\tARUN \t\t78\n",
+ "\n",
+ "\n",
+ " 102 \t\tDEEPAK \t\t72\n",
+ "\n",
+ "\n",
+ " 103 \t\tSUSHMITHA \t\t86\n",
+ "\n",
+ "\n",
+ " 104 \t\tRAHUL \t\t67\n",
+ "\n",
+ "\n",
+ "--------------------------------------------------------\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6, Page Number : FLS-14"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "source_name = raw_input(\"\\nEnter the source file name : \")\n",
+ "\n",
+ "source_fptr = open(source_name,\"r\")\n",
+ "\n",
+ "target_name = raw_input(\"\\nEnter the target file name : \")\n",
+ "target_fptr = open(target_name,\"w+\")\n",
+ "\n",
+ "if source_fptr == 0:\n",
+ " print \"\\nNo content/source file !!!\"\n",
+ " print \"\\n press any key...\"\n",
+ "else:\n",
+ " while True:\n",
+ " ch = source_fptr.read(1)\n",
+ " if not ch:\n",
+ " break\n",
+ " target_fptr.write(\"%c\"%(ch))\n",
+ " \n",
+ "target_fptr.close()\n",
+ "target_fptr = open(target_name,\"r\")\n",
+ "\n",
+ "print \"\\nThe contents of the target file are\"\n",
+ "print \"\\n---------------------------------------\\n\"\n",
+ "lines = target_fptr.readlines()\n",
+ "\n",
+ "for line in lines:\n",
+ " print line\n",
+ " \n",
+ "target_fptr.close()\n",
+ "source_fptr.close()\n",
+ "print \"\\n\\n Press any key...\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter the source file name : SAMPLE.TXT\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter the target file name : SAMPLE.BAK\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "The contents of the target file are\n",
+ "\n",
+ "---------------------------------------\n",
+ "\n",
+ "Computer Programming in C language is widely used for Science and Engineering applications.\n",
+ "\n",
+ "\n",
+ " Press any key...\n"
+ ]
+ }
+ ],
+ "prompt_number": 26
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7, Page Number : FLS-15"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "ch = 'y'\n",
+ "\n",
+ "while ch == 'y' or ch == 'Y':\n",
+ " print \"\\n\\t MENU\"\n",
+ " print \"\\n\\t-------------------------------------------\"\n",
+ " print \"\\n\\tPress 1 to create data file\"\n",
+ " print \"\\n\\t 2 to find smallest & largest integer\"\n",
+ " \n",
+ " choice = int(raw_input(\"\\n\\n\\tEnter your choice : \"))\n",
+ " \n",
+ " if choice == 1:\n",
+ " data_file = open(\"DATAFILE\",\"w\")\n",
+ " n = int(raw_input(\"\\nEnter data, enter 0 at end of reading\\n\"))\n",
+ " while n != 0:\n",
+ " data_file.write(\"%d\\n\"%(n))\n",
+ " n = int(raw_input(\"\"))\n",
+ " data_file.close()\n",
+ " else:\n",
+ " if choice == 2:\n",
+ " data_file = open(\"DATAFILE\",\"r\")\n",
+ " n1 = data_file.readlines()\n",
+ " n = n1[0]\n",
+ " big = n\n",
+ " small = n\n",
+ " for n in n1:\n",
+ " if n > big:\n",
+ " big = n \n",
+ " if n < small:\n",
+ " small = n\n",
+ " \n",
+ " data_file.close()\n",
+ " print \"\\nLargest integer is \",big\n",
+ " print \"\\nSmallest integer is \",small\n",
+ " else:\n",
+ " print \"\\nWrong choice !!!\" \n",
+ " ch = raw_input(\"\\n\\nPress Y to continue, any other key to stop...\")\n",
+ " \n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\t MENU\n",
+ "\n",
+ "\t-------------------------------------------\n",
+ "\n",
+ "\tPress 1 to create data file\n",
+ "\n",
+ "\t 2 to find smallest & largest integer\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ "\tEnter your choice : 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter data, enter 0 at end of reading\n",
+ "23\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "76\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-56\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "876\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "52\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ "Press Y to continue, any other key to stop...y\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\t MENU\n",
+ "\n",
+ "\t-------------------------------------------\n",
+ "\n",
+ "\tPress 1 to create data file\n",
+ "\n",
+ "\t 2 to find smallest & largest integer\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ "\tEnter your choice : 2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Largest integer is 876\n",
+ "\n",
+ "\n",
+ "Smallest integer is -56\n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ "Press Y to continue, any other key to stop...n\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8, Page Number : FLS-20"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import os\n",
+ "\n",
+ "class emp_record:\n",
+ " eno = 0\n",
+ " ename = ''\n",
+ " bpay = 0.0\n",
+ " \n",
+ "erec = emp_record()\n",
+ "\n",
+ "def creatfile():\n",
+ " choice = 'y'\n",
+ " efile = open(\"EMPLOY.DAT\",\"w\")\n",
+ " while choice.upper() == 'Y':\n",
+ " erec.eno = int(raw_input(\"\\nEnter the employee No.\"))\n",
+ " erec.ename = raw_input(\"\\nEmployee Name ?\")\n",
+ " erec.bpay = float(raw_input(\"\\nBasic pay ?\"))\n",
+ " efile.write(\"%d %s %f\\n\"%(erec.eno,erec.ename,erec.bpay))\n",
+ " print \"\\n Press Y - to continue\"\n",
+ " print \"\\n any other key to stop.\"\n",
+ " choice = raw_input(\"\")\n",
+ " efile.close()\n",
+ " \n",
+ "def readfile():\n",
+ " eno = 0\n",
+ " ename = ''\n",
+ " bpay = 0.0\n",
+ " efile = open(\"EMPLOY.DAT\",\"r\")\n",
+ " print \"\\n----------------------------------------------------\"\n",
+ " print \"\\n Emp.No. Employee Name Basic pay\"\n",
+ " print \"\\n----------------------------------------------------\"\n",
+ " lines = efile.readlines()\n",
+ " \n",
+ " for line in lines:\n",
+ " eno,ename,bpay = line.split(' ')\n",
+ " print \"\\n\",eno,\"\\t\",ename,\"\\t\",bpay\n",
+ " print \"\\n----------------------------------------------------\"\n",
+ "\n",
+ "def appendrec():\n",
+ " choice = 'y'\n",
+ " efile = open(\"EMPLOY.DAT\",\"a\")\n",
+ " while choice.upper() == 'Y':\n",
+ " erec.eno = int(raw_input(\"\\nEnter the employee No. \"))\n",
+ " erec.ename = raw_input(\"\\nEmployee Name ? \")\n",
+ " erec.bpay = float(raw_input(\"\\nBasic pay ?\"))\n",
+ " efile.write(\"%d %s %f\\n\"%(erec.eno,erec.ename,erec.bpay))\n",
+ " print \"\\nPress Y - to continue\"\n",
+ " print \"\\n any other key to stop.\"\n",
+ " choice = raw_input(\"\")\n",
+ " efile.close()\n",
+ " \n",
+ "def modirec():\n",
+ " flag = 0\n",
+ " eno = 0\n",
+ " ename = ''\n",
+ " bpay = 0.0\n",
+ " efile = open(\"EMPLOY.DAT\",\"r+\")\n",
+ " print \"\\nTo modify a record \"\n",
+ " print \"\\n------------------\"\n",
+ " temp = int(raw_input(\"\\nEnter the Roll No.\"))\n",
+ " lines = efile.readlines()\n",
+ " for line in lines:\n",
+ " #while True and flag == 0:\n",
+ " eno,ename,bpay = line.split(' ')\n",
+ " if eno == temp:\n",
+ " print \"\\nExisting record details\"\n",
+ " print \"\\n\",eno,\"\\t\",ename,\"\\t\",bpay\n",
+ " print \"\\n\\nEnter the modified details\"\n",
+ " print \"\\n------------------------------\"\n",
+ " erec.eno = int(raw_input(\"\\nEnter the employee No. \"))\n",
+ " erec.ename = raw_input(\"\\nEmployee Name ? \")\n",
+ " erec.bpay = float(raw_input(\"\\nBasic pay ?\"))\n",
+ " efile.write(\"%d %s %f\\n\"%(erec.eno,erec.ename,erec.bpay))\n",
+ " flag = 1\n",
+ " print \"\\nThe record has been modified!\"\n",
+ " efile.close()\n",
+ " if flag == 0:\n",
+ " print \"\\nThe given record is not present in the file!!!\"\n",
+ " print \"\\nPress any key to continue ...\"\n",
+ " \n",
+ "def deleterec():\n",
+ " flag = 0\n",
+ " eno = 0\n",
+ " ename = ''\n",
+ " bpay = 0.0\n",
+ " efile = open(\"EMPLOY.DAT\",\"r\")\n",
+ " tfile = open(\"TEMP.DAT\",\"w\")\n",
+ " print \"\\nTo delete a record\"\n",
+ " print \"\\n------------------\"\n",
+ " temp = int(raw_input(\"\\nEnter the Roll No.\"))\n",
+ " while True:\n",
+ " eno,ename,bpay = efile.readline().split(' ')\n",
+ " if eno == temp:\n",
+ " print \"\\nExisting record details\"\n",
+ " print \"\\n\",eno,\"\\t\",ename,\"\\t\",bpay\n",
+ " print \"\\n is deleted!!!\"\n",
+ " flag = 1\n",
+ " tfile.write(\"%d %s %f\\n\"%(eno,ename,bpay))\n",
+ " tfile.close()\n",
+ " efile.close()\n",
+ " os.remove(\"EMPLOY.DAT\")\n",
+ " os.rename(\"TEMP.DAT\",\"EMPLOY.DAT\")\n",
+ " if flag == 0:\n",
+ " print \"\\nThe given record is not present in the file!!!\"\n",
+ " print \"\\n\\tpress any key to continue...\"\n",
+ " \n",
+ "n = 0\n",
+ "while n != 6:\n",
+ " print \"\\n\\tMain Menu\"\n",
+ " print \"\\n\\t Press 1 - file creation\"\n",
+ " print \"\\n\\t 2 - reading\"\n",
+ " print \"\\n\\t 3 - appending\"\n",
+ " print \"\\n\\t 4 - modify a record\"\n",
+ " print \"\\n\\t 5 - delete a record\"\n",
+ " print \"\\n\\t 6 - quit\"\n",
+ " n = int(raw_input(\"\\n\\nEnter your choice : \"))\n",
+ " \n",
+ " if n == 1:\n",
+ " creatfile()\n",
+ " else:\n",
+ " if n == 2:\n",
+ " readfile()\n",
+ " else:\n",
+ " if n == 3:\n",
+ " appendrec()\n",
+ " else:\n",
+ " if n == 4:\n",
+ " modirec()\n",
+ " else:\n",
+ " if n == 5:\n",
+ " deleterec()\n",
+ " \n",
+ " \n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\tMain Menu\n",
+ "\n",
+ "\t Press 1 - file creation\n",
+ "\n",
+ "\t 2 - reading\n",
+ "\n",
+ "\t 3 - appending\n",
+ "\n",
+ "\t 4 - modify a record\n",
+ "\n",
+ "\t 5 - delete a record\n",
+ "\n",
+ "\t 6 - quit\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ "Enter your choice : 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter the employee No.2101\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Employee Name ?ARUN\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Basic pay ?8500\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ " Press Y - to continue\n",
+ "\n",
+ " any other key to stop.\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Y\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter the employee No.2102\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Employee Name ?DEEPAK\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Basic pay ?8000\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ " Press Y - to continue\n",
+ "\n",
+ " any other key to stop.\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "N\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\tMain Menu\n",
+ "\n",
+ "\t Press 1 - file creation\n",
+ "\n",
+ "\t 2 - reading\n",
+ "\n",
+ "\t 3 - appending\n",
+ "\n",
+ "\t 4 - modify a record\n",
+ "\n",
+ "\t 5 - delete a record\n",
+ "\n",
+ "\t 6 - quit\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ "Enter your choice : 2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "----------------------------------------------------\n",
+ "\n",
+ " Emp.No. Employee Name Basic pay\n",
+ "\n",
+ "----------------------------------------------------\n",
+ "\n",
+ "2101 \tARUN \t8500.000000\n",
+ "\n",
+ "\n",
+ "2102 \tDEEPAK \t8000.000000\n",
+ "\n",
+ "\n",
+ "----------------------------------------------------\n",
+ "\n",
+ "\tMain Menu\n",
+ "\n",
+ "\t Press 1 - file creation\n",
+ "\n",
+ "\t 2 - reading\n",
+ "\n",
+ "\t 3 - appending\n",
+ "\n",
+ "\t 4 - modify a record\n",
+ "\n",
+ "\t 5 - delete a record\n",
+ "\n",
+ "\t 6 - quit\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ "Enter your choice : 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter the employee No. 2103\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Employee Name ? SUSHMITHA\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Basic pay ?6400\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press Y - to continue\n",
+ "\n",
+ " any other key to stop.\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Y\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter the employee No. 2104\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Employee Name ? ASHIKA\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Basic pay ?6200\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press Y - to continue\n",
+ "\n",
+ " any other key to stop.\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "N\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\tMain Menu\n",
+ "\n",
+ "\t Press 1 - file creation\n",
+ "\n",
+ "\t 2 - reading\n",
+ "\n",
+ "\t 3 - appending\n",
+ "\n",
+ "\t 4 - modify a record\n",
+ "\n",
+ "\t 5 - delete a record\n",
+ "\n",
+ "\t 6 - quit\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ "Enter your choice : 4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "To modify a record \n",
+ "\n",
+ "------------------\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter the Roll No.2101\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "The given record is not present in the file!!!\n",
+ "\n",
+ "Press any key to continue ...\n",
+ "\n",
+ "\tMain Menu\n",
+ "\n",
+ "\t Press 1 - file creation\n",
+ "\n",
+ "\t 2 - reading\n",
+ "\n",
+ "\t 3 - appending\n",
+ "\n",
+ "\t 4 - modify a record\n",
+ "\n",
+ "\t 5 - delete a record\n",
+ "\n",
+ "\t 6 - quit\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ "Enter your choice : 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "To delete a record\n",
+ "\n",
+ "------------------\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter the Roll No.2102\n"
+ ]
+ },
+ {
+ "ename": "ValueError",
+ "evalue": "need more than 1 value to unpack",
+ "output_type": "pyerr",
+ "traceback": [
+ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)",
+ "\u001b[1;32m<ipython-input-1-5b4dfc956b00>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 128\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 129\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mn\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;36m5\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 130\u001b[1;33m \u001b[0mdeleterec\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 131\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 132\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
+ "\u001b[1;32m<ipython-input-1-5b4dfc956b00>\u001b[0m in \u001b[0;36mdeleterec\u001b[1;34m()\u001b[0m\n\u001b[0;32m 89\u001b[0m \u001b[0mtemp\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mraw_input\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"\\nEnter the Roll No.\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 90\u001b[0m \u001b[1;32mwhile\u001b[0m \u001b[0mTrue\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 91\u001b[1;33m \u001b[0meno\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mename\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mbpay\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mefile\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mreadline\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msplit\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m' '\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 92\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0meno\u001b[0m \u001b[1;33m==\u001b[0m \u001b[0mtemp\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 93\u001b[0m \u001b[1;32mprint\u001b[0m \u001b[1;34m\"\\nExisting record details\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
+ "\u001b[1;31mValueError\u001b[0m: need more than 1 value to unpack"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file