0% found this document useful (0 votes)
13 views

Computer Python Programing Project

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Computer Python Programing Project

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

COMPUTER PYTHON PROGRAMING

PROJECT

SUBMITTED BY: GT. RITHISH


CLASS: XII ‘A’

S.NO EXPERIMENT

1 COUNTING VOWELS, CONSONANTS AND SPECIAL LETTER IN A FILE

2 SIMPLE ARITHEMETIC CALCULATOR

3 COPYING A TEXT FILE EXECPT FOR THOSE LINES CONTAINING LETTER ‘a’

4 DISPLAY EMPLOYEE NAME AND SALARY IF EXIST EMPLOYEE NUMBER IN THE


CSV FILE

1
COUNTING VOWELS, CONSONANTS AND SPECIAL LETTER IN A FILE

PROGRAME:
 f=open('File1.txt')
 v=0
 c=0
 u=0
 o=0
 data=f.read()
 vowelS = ['a','e','i','o','u']
 for ch in data:
 if ch.isalpha():
 if ch.lower() in vowels:
 v=v+1
 else:
 c=c+1
 if ch.isupper():
 u=u+1
 elif ch.islower():
 l=l+1
 elif ch!='' and ch!='\n':
 o=o+1
 print('Total Vowels in the file:',v)
 print('Total Conconants in the file:',n)
 print('Total Capital letter in file:',u)
 print('Total Small letter in fiel:',l)
 print('Total Other than letter:',o)
 f.close()

File1.txt:
India is my country

2
I love python
Python learning is fun
OUTPUT:
 Total Vowels in the file: 16
 Total Consonants in the file: 30
 Total Capital letter in file: 3
 Total Small letter in file: 43
 Total Other than letter: 0

3
SIMPLE ARITHEMETIC CALCULATOR
PROGRAME:
 def add(x,y):
 return x+y
 def subract(x,y):
 return x-y
 def multiply(x,y):
 return x*y
 def divide(x,y):
 return x/y
 def floordiv(x,y):
 return x//y
 def moddiv(x,y):
 return x%y
 #Take input from the user
 print('Select operation.')
 print('1 - Add')
 print('2 - Sub')
 print('3 - Multiply')
 print('4 - Divide')
 print('5 - Floor Division')
 print('6 - Modulo Division')
 ch=int(input("Enter the choice"))
 while ch<7:
 num1 = int(input('Enter the first number:'))
 num2 = int(input('Enter the second number:'))
 if ch==1:
 print(num1,'+',num2,'=',add(num1,num2))
 elif ch==2:
 print(num1,'-',num2,'=',subract(num1,num2))
 elif ch==3:

4
 print(num1,'*',num2,'=',multiply(num1,num2))
 elif ch==4:
 print(num1,'/',num2,'=',divide(num1,num2))
 elif ch==5:
 print(num1,'//',num2,'=',floordiv(num1,num2))
 elif ch==6:
 print(num1,'%',num2,'=',moddiv(num1,num2))
 ch=int(input("Enter the choice"))
 print('Exit')

OUTPUT
 Select operation.
 1 - Add
 2 - Sub
 3 - Multiply
 4 - Divide
 5 - Floor Division
 6 - Modulo Division
 Enter the choice1
 Enter the first number:5
 Enter the second number:5
 5 + 5 = 10
 Enter the choice2
 Enter the first number:5
 Enter the second number:5
 5-5=0
 Enter the choice3
 Enter the first number:5

5
 Enter the second number:5
 5 * 5 = 25
 Enter the choice4
 Enter the first number:5
 Enter the second number:5
 5 / 5 = 1.0
 Enter the choice5
 Enter the first number:5
 Enter the second number:5
 5 // 5 = 1
 Enter the choice6
 Enter the first number:5
 Enter the second number:5
 5%5=0
 Enter the choice7
 Exit

6
COPYING A TEXT FILE EXECPT FOR THOSE LINES
CONTAINING LETTER ‘a’
PROGRAME:
 f1=open('file1.txt')
 f2=open('file1copy.txt','w')
 for line in f1:
 if 'a' not in line:
 f2.write(line)
 print('##File Copied Successfully!##')
 f1.close()
 f2.close()

File 1.txt:
A quick brown fox
one two three four
five six seven
India is my country
eight nine ten

File 1copy.txt:
one two three four
five six seven
eight nine ten

7
DISPLAY EMPLOYEE NAME AND SALARY IF EXIST
EMPLOYEE NUMBER IN THE CSV FILE
PROGRAME
 import csv
 with open('myfile.cvs',mode='a')as csvfile:
 mywriter = csv.writer(csvfile,delimiter = ',')
 ans = 'y'
 while ans.lower()=='y':
 eno=int(input('Enter the Employee Number'))
 name=input('Enter Employ Name')
 salary=int(input('Enter the Employee Salary:'))
 mywriter.writerow([eno,name,salary])
 print('#Data Saved...##')
 ans=input('Add More ?')
 ans='y'
 with open('myfile.csv',mode='r') as csvfile:
 while ans.lower()=='y':
 myreader = csv.reader(csvfile,delimiter =',')
 found = False
 e =int(input('Enter Employee Number to search:'))
 for row in myreader:
 if len(row)!=0:
 if int(row[0])==e:
 print('====================')
 print('NAME :',row[1])
 print('SALARY :',row[2])
 found = True
 break
 if not found:
 print('====================')
 print('EMPNO NOT FOUND')

8
 print('====================')
 csvfile.seek(0)
 ans=input('Search More?(Y)')

OUTPUT
 Enter the Employee Number1
 Enter Employ Name: CLARE
 Enter the Employee Salary:150000
 #Data Saved...##
 Add More ?Y
 Enter the Employee Number2
 Enter Employ Name: OVEN GRADY
 Enter the Employee Salary:300000
 #Data Saved...##
 Add More ?N
 Enter Employee Number to search :1
 ================================
 NAME : CLARE
 SALARY : 150000
 Search More ? (Y)Y
 Enter Employee Number to search :2
 ================================
 NAME : OVEN GRADY
 SALARY : 300000
 Search More ? (Y)

You might also like