0% found this document useful (0 votes)
60 views17 pages

CS PRAC FILE WORK - Ipynb - Colaboratory

The document contains Python code snippets that perform various tasks like counting characters, digits, and words in a string; creating lists of positive and negative numbers from an input list; storing contacts in a dictionary; printing patterns; and checking if a number is a palindrome. The code takes user input, performs operations like sorting, adding, removing elements, and prints output like lists, dictionaries, and patterns.

Uploaded by

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

CS PRAC FILE WORK - Ipynb - Colaboratory

The document contains Python code snippets that perform various tasks like counting characters, digits, and words in a string; creating lists of positive and negative numbers from an input list; storing contacts in a dictionary; printing patterns; and checking if a number is a palindrome. The code takes user input, performs operations like sorting, adding, removing elements, and prints output like lists, dictionaries, and patterns.

Uploaded by

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

11/9/21, 10:09 PM CS PRAC FILE WORK.

ipynb - Colaboratory

Name:-Akanksha Sharma

Class:-XII-A

Roll No.:04

'''Write a program to input line(s) of text from the user until enter is pressed. Count th
 total number of digits, total number of special symbols and total number of words in the 

line=input('Enter line(s)') 
Ch=0
a=0 
d=0 
s=0 
word=0 
for i in line: 
  Ch+=1 
for j in line: 
  if j.isalpha()==True: 
    a+=1 
  elif j.isdigit()==True: 
    d+=1 
  elif j==' ': 
    continue 
  else: 
    s+=1 
for i in line:
  word=1 
for e in line: 
  if e.isspace()==True: 
    word+=1
print('The total number of characters in the text =',Ch) 
print('The total number of alphabets in the text =',a) 
print('The total number of digits in the text =',d) 
print('The total number of special symbols in the text =',s) 
print('The total number of words in the text =',word)

for i in line:
  if i in 'aeiou':
    line.replace(i,'*')

Enter line(s)My name is @k@nksh@

The total number of characters in the text = 19

The total number of alphabets in the text = 13

The total number of digits in the text = 0

The total number of special symbols in the text = 3

The total number of words in the text = 4

'''Write a program to read a list of n integers (positive as well as negative). Create two 
 the given list. Print all three lists. Also find  and display the largest element and the 
n=int(input('Enter number of elements present in the list:'))

list1=[]

pos=[]

https://colab.research.google.com/drive/1jlq4P9j0ZE_nPL-CrcDCzXwyNGF_da_Y#scrollTo=yz1uM6ZSMev1&uniqifier=3&printMode=true 1/17
11/9/21, 10:09 PM CS PRAC FILE WORK.ipynb - Colaboratory

neg=[]

for i in range(0,n):

   a=int(input('Enter the numbers to be added in the list.'))

   list1+=[a]

print(list1,'is the original list')

for j in list1:

  if j>=0:

    pos+=[j]

  else:

    neg+=[j]

print('The list of positive numbers is:' ,pos )

print('The list of negative numbers is:',neg)

print(max(list1),'is the largest element of the list')

list1.remove(max(list1))

print(max(list1),'is the second largest element of the list')

Enter number of elements present in the list:10

Enter the numbers to be added in the list.-1

Enter the numbers to be added in the list.-2

Enter the numbers to be added in the list.-3

Enter the numbers to be added in the list.1

Enter the numbers to be added in the list.2

Enter the numbers to be added in the list.2

Enter the numbers to be added in the list.6

Enter the numbers to be added in the list.3

Enter the numbers to be added in the list.4

Enter the numbers to be added in the list.-5

[-1, -2, -3, 1, 2, 2, 6, 3, 4, -5] is the original list

The list of positive numbers is: [1, 2, 2, 6, 3, 4]

The list of negative numbers is: [-1, -2, -3, -5]

6 is the largest element of the list

4 is the second largest element of the list

'''Write a program to input your friends’ names and their Phone Numbers and store them in 
a) Display the name and phone number of all your friends b) Add a new key-value pair in th
dictionary d) Modify the phone number of an existing friend e) Check if a friend is presen
phone={}

n=int(input('Enter the number of friends for whom you wish to save the number'))

for i in range(0,n):

  a=input('Enter name of friend:')

  b=int(input('Enter phone number of your friend:'))

  phone[a]=b

print('Name\t:\tPhone Number')

for j in phone:

  print(j,'\t:\t',phone[j])

c=input('Enter name of friend to add in directory:')

phone[c]=int(input('Enter phone number of your friend:'))

print(phone,'is the new phone directory')

e=input('Enter name of friend to remove from the dictionary:')

del phone[e]

print(phone,'is the new phone directory')

https://colab.research.google.com/drive/1jlq4P9j0ZE_nPL-CrcDCzXwyNGF_da_Y#scrollTo=yz1uM6ZSMev1&uniqifier=3&printMode=true 2/17
11/9/21, 10:09 PM CS PRAC FILE WORK.ipynb - Colaboratory

f=input('Enter name of friend for whom you want to change phone number:')

phone[f]=int(input('Enter the new phone number of your friend'))

print(phone,'is the new phone directory')

g=input('Enter name of friend to find in the dictionary:')

print(phone.get(g),'is the phone number of friend',g

      )

list1=[]

for i in phone:

  list1+=[i]

list1.sort()

newp={}

for i in list1:

  newp[i]=phone[i]

print(newp,'is the sorted phone directory')

Enter the number of friends for whom you wish to save the number3

Enter name of friend:abc

Enter phone number of your friend:12341234

Enter name of friend:xyz

Enter phone number of your friend:56785678

Enter name of friend:pqr

Enter phone number of your friend:159951

Name : Phone Number

abc : 12341234

xyz : 56785678

pqr : 159951

Enter name of friend to add in directory:z

Enter phone number of your friend:1237475

{'abc': 12341234, 'xyz': 56785678, 'pqr': 159951, 'z': 1237475} is the new phone dire
Enter name of friend to remove from the dictionary:xyz

{'abc': 12341234, 'pqr': 159951, 'z': 1237475} is the new phone directory

Enter name of friend for whom you want to change phone number:pqr

Enter the new phone number of your friend55522233

{'abc': 12341234, 'pqr': 55522233, 'z': 1237475} is the new phone directory

Enter name of friend to find in the dictionary:abc

12341234 is the phone number of friend abc

{'abc': 12341234, 'pqr': 55522233, 'z': 1237475} is the sorted phone directory

'''Pattern-1

1 2 3 4 5

1 2 3 4

1 2 3

1 2

1 '''

n=6

while True:

  for i in range(1,n):

    print(i,end=' ')

    if i==n-1:

      print('\r')

https://colab.research.google.com/drive/1jlq4P9j0ZE_nPL-CrcDCzXwyNGF_da_Y#scrollTo=yz1uM6ZSMev1&uniqifier=3&printMode=true 3/17
11/9/21, 10:09 PM CS PRAC FILE WORK.ipynb - Colaboratory

  n-=1

  if n==0:

    break

1 2 3 4 5

1 2 3 4

1 2 3

1 2

'''Pattern-1 i)

2 2

3 3 3

4 4 4 4

5 5 5 5 5'''

for i in range(1,6):

  for j in range(1,i+1):

      print(i,end=' ')

  print('\r')

2 2

3 3 3

4 4 4 4

5 5 5 5 5

'''Pattern-1 ii)

    1

   121

  12321

 1234321

123454321

'''

for i in range(1,6):

  for j in range(1,6-i):

    print(' ',end='')

  for j in range(1,i+1):

    print(j,end='')

  for j in range(i-1,0,-1):

    print(j,end='')

  print('')

121

12321

1234321

123454321

'''Pattern-2

AB

ABC

https://colab.research.google.com/drive/1jlq4P9j0ZE_nPL-CrcDCzXwyNGF_da_Y#scrollTo=yz1uM6ZSMev1&uniqifier=3&printMode=true 4/17
11/9/21, 10:09 PM CS PRAC FILE WORK.ipynb - Colaboratory

ABCD

ABCDE'''

for i  in range(1,6):

    for j in range(65,65+i):

        a =  chr(j)

        print (a,end='')

    print('\r')

AB

ABC

ABCD

ABCDE

'''Pattern-2 i)

ABCDE

ABCD

ABC

AB

'''

for i in range(5,0,-1):

  for j in range(65,65+i):

    a=chr(j)

    print(a,end='')

  print('\r')

ABCDE

ABCD

ABC

AB

'''Pattern-2 ii)

BB

CCC

DDDD

EEEEE

'''

for i in range(1,6):

  for j in range(65,i+65):

    a=chr(j)

  for k in range(1,i+1):

    print(a,end='')

  print('\r')

BB

CCC

DDDD

EEEEE

'''WAP to input a number and perform following -                                           

https://colab.research.google.com/drive/1jlq4P9j0ZE_nPL-CrcDCzXwyNGF_da_Y#scrollTo=yz1uM6ZSMev1&uniqifier=3&printMode=true 5/17
11/9/21, 10:09 PM CS PRAC FILE WORK.ipynb - Colaboratory

1. count even,odd and total  digits                                                        
2. find sum and product of even, odd digits                                                
3. find whether number is a palindrome or not'''

sumeve=0

proeve=1

even=0

sumodd=0

proodd=1

odd=0

a=int(input('Enter a number:'))

count=len(str(a))

for i in str(a):

  if int(i)%2==0:

    sumeve+=int(i)

    proeve*=int(i)

    even+=1

  else:

    sumodd+=int(i)

    proodd*=int(i)

    odd+=1

print('Number of even digits:',even,'\nNumber of odd digits:',odd,'\nNumber of digits:',co
b=str(a)[::-1]

if a==int(b):

  print(a,'is a palindrome')

else:

  print(a,'is not a palindrome')

Enter a number:212

Number of even digits: 2

Number of odd digits: 1

Number of digits: 3

Sum of even digits: 4

Product of even digits: 4

Sum of odd digits: 1

Product of odd digits: 1

212 is a palindrome

''' WAP USING udf'S TO PRINT YOUR REPORT CARD BY USING VALIDATION CHECKS '''  

name=input('Enter Name -->')

cla=input('Enter Class -->')

adm=int(input('Enter Admission Number -->'))

rol=int(input('Enter Roll Number -->'))

mathth=int(input("enter Math theory   ->"))

mathpr=int(input("enter Maths practical   ->"))

csth=int(input("enter CS theory   ->"))

cspr=int(input("enter CS practical   ->"))

phyth=int(input("enter Phy theory   ->"))

phypr=int(input("enter Phy practical   ->"))

chmth=int(input("enter Chem theory   ->"))

chmpr=int(input("enter Chem practical   ->"))

ength=int(input("enter English theory   ->"))

engasl=int(input("enter English ASL   ->"))

while True:

  if mathth>80 or mathpr>20:

    print('Reinput the correct marks')

https://colab.research.google.com/drive/1jlq4P9j0ZE_nPL-CrcDCzXwyNGF_da_Y#scrollTo=yz1uM6ZSMev1&uniqifier=3&printMode=true 6/17
11/9/21, 10:09 PM CS PRAC FILE WORK.ipynb - Colaboratory

    mathth=int(input("enter Math theory   ->"))

    mathpr=int(input("enter Maths practical   ->"))

  elif ength>80 or engasl>20:

    print('Reinput the correct marks')

    ength=int(input("enter English theory   ->"))

    engasl=int(input("enter English ASL   ->"))

  elif csth>70 or cspr>30:

    print('Reinput the correct marks')

    csth=int(input("enter CS theory   ->"))

    cspr=int(input("enter CS practical   ->"))

  elif phyth>70 or phypr>30:

    print('Reinput Correct Marks')

    phyth=int(input("enter Phy theory   ->"))

    phypr=int(input("enter Phy practical   ->"))

  elif chmth>70 or chmpr>30:

    print('Reinput correct Marks')

    chmth=int(input("enter Chem theory   ->"))

    chmpr=int(input("enter Chem practical   ->"))

  else:

    break

def line(n):

    print('-'*n)

def prtheader():

  print("\t\t\t   PROGRESS REPORT  SESSION 2021-22 ")

  print("ADMISSION NO.   :",adm,'\t\t',"NAME  :", name)

  print("ROLL NO.   :",rol,'\t\t\t',"CLASS-SEC  :",cla)

  line(90)

  print("SUBJECT",'\t\t\t',"MARKS(THEORY)",'\t\t',"MARKS (PRACTICAL)",'\t', "TOTAL")

def repcard():

  print("ENGLISH",'\t\t\t\t',ength,'\t\t\t',engasl,'\t\t',ength+engasl)

  print("MATHS",'\t\t\t\t\t',mathth,'\t\t\t',mathpr,'\t\t',mathth+mathpr)

  print("PHYSICS",'\t\t\t\t',phyth,'\t\t\t',phypr,'\t\t',phyth+phypr)

  print("CHEMISTRY",'\t\t\t\t',chmth,'\t\t\t',chmpr,'\t\t',chmth+chmpr)

  print("CS",'\t\t\t\t\t',csth,'\t\t\t',cspr,'\t\t',csth+cspr)

def printreport():

  line(90)

  prtheader()

  line(90)

  repcard()

  line(90)

printreport()

Enter Name -->Akanksha Sharma

Enter Class -->XII-A

Enter Admission Number -->20200311

Enter Roll Number -->04

enter Math theory ->78

enter Maths practical ->20

enter CS theory ->70

enter CS practical ->30

enter Phy theory ->60

https://colab.research.google.com/drive/1jlq4P9j0ZE_nPL-CrcDCzXwyNGF_da_Y#scrollTo=yz1uM6ZSMev1&uniqifier=3&printMode=true 7/17
11/9/21, 10:09 PM CS PRAC FILE WORK.ipynb - Colaboratory

enter Phy practical ->28

enter Chem theory ->68

enter Chem practical ->29

enter English theory ->79

enter English ASL ->20

-------------------------------------------------------------------------------------
PROGRESS REPORT SESSION 2021-22

ADMISSION NO. : 20200311 NAME : Akanksha Sharma

ROLL NO. : 4 CLASS-SEC : XII-A

-------------------------------------------------------------------------------------
SUBJECT MARKS(THEORY) MARKS (PRACTICAL) TOTA
-------------------------------------------------------------------------------------
ENGLISH 79 20 99

MATHS 78 20 98

PHYSICS 60 28 88

CHEMISTRY 68 29 97

CS 70 30 100

-------------------------------------------------------------------------------------

'''

WAP USING udf's and dictionary TO PRINT YOUR REPORT CARD BY USING VALIDATION   CHECKS'''

name=input('Enter Name -->')

cla=input('Enter Class -->')

adm=int(input('Enter Admission Number -->'))

rol=int(input('Enter Roll Number -->'))

mathth=int(input("enter Math theory   ->"))

mathpr=int(input("enter Maths practical   ->"))

csth=int(input("enter CS theory   ->"))

cspr=int(input("enter CS practical   ->"))

phyth=int(input("enter Phy theory   ->"))

phypr=int(input("enter Phy practical   ->"))

chmth=int(input("enter Chem theory   ->"))

chmpr=int(input("enter Chem practical   ->"))

ength=int(input("enter English theory   ->"))

engasl=int(input("enter English ASL   ->"))

while True:

  if mathth>80 or mathpr>20:

    print('Reinput the correct marks')

    mathth=int(input("enter Math theory   ->"))

    mathpr=int(input("enter Maths practical   ->"))

  elif ength>80 or engasl>20:

    print('Reinput the correct marks')

    ength=int(input("enter English theory   ->"))

    engasl=int(input("enter English ASL   ->"))

  elif csth>70 or cspr>30:

    print('Reinput the correct marks')

    csth=int(input("enter CS theory   ->"))

    cspr=int(input("enter CS practical   ->"))

  elif phyth>70 or phypr>30:

    print('Reinput Correct Marks')

    phyth=int(input("enter Phy theory   ->"))

    phypr=int(input("enter Phy practical   ->"))

  elif chmth>70 or chmpr>30:

    print('Reinput correct Marks')

    chmth=int(input("enter Chem theory   ->"))

https://colab.research.google.com/drive/1jlq4P9j0ZE_nPL-CrcDCzXwyNGF_da_Y#scrollTo=yz1uM6ZSMev1&uniqifier=3&printMode=true 8/17
11/9/21, 10:09 PM CS PRAC FILE WORK.ipynb - Colaboratory

    chmpr=int(input("enter Chem practical   ->"))

  else:

    break

def line(n):

    print('-'*n)

def prtheader():

  print("\t\t\t   PROGRESS REPORT  SESSION 2021-22 ")

  print("ADMISSION NO.   :",adm,'\t\t',"NAME  :", name)

  print("ROLL NO.   :",rol,'\t\t\t',"CLASS-SEC  :",cla)

  line(90)

  print("SUBJECT",'\t\t\t',"MARKS(THEORY)",'\t\t',"MARKS (PRACTICAL)")

Marks={'Maths Theory': mathth , 'Maths Practical': mathpr , 'CS Theory': csth , 'CS Practi

def Mark():

  print("ENGLISH",'\t\t\t\t',Marks.get('English Theory'),'\t\t\t',Marks.get('English ASL')
  print("MATHS",'\t\t\t\t\t',Marks.get('Maths Theory'),'\t\t\t',Marks.get('Maths Practical
  print("PHYSICS",'\t\t\t\t',Marks.get('Phy Theory'),'\t\t\t',Marks.get('Phy Practical'))

  print("CHEMISTRY",'\t\t\t\t',Marks.get('Chem Theory'),'\t\t\t',Marks.get('Chem Practical
  print("CS",'\t\t\t\t\t',Marks.get('CS Theory'),'\t\t\t',Marks.get('CS Practical'))

def printreport():

  line(90)

  prtheader()

  line(90)

  Mark()

  line(90)

printreport()

Enter Name -->Akanksha Sharma

Enter Class -->XII-A

Enter Admission Number -->20200311

Enter Roll Number -->04

enter Math theory ->78

enter Maths practical ->20

enter CS theory ->70

enter CS practical ->30

enter Phy theory ->60

enter Phy practical ->28

enter Chem theory ->68

enter Chem practical ->29

enter English theory ->79

enter English ASL ->20

-------------------------------------------------------------------------------------
PROGRESS REPORT SESSION 2021-22

ADMISSION NO. : 20200311 NAME : Akanksha Sharma

ROLL NO. : 4 CLASS-SEC : XII-A

-------------------------------------------------------------------------------------
SUBJECT MARKS(THEORY) MARKS (PRACTICAL)

-------------------------------------------------------------------------------------
ENGLISH 79 20

MATHS 78 20

PHYSICS 60 28

CHEMISTRY 68 29

https://colab.research.google.com/drive/1jlq4P9j0ZE_nPL-CrcDCzXwyNGF_da_Y#scrollTo=yz1uM6ZSMev1&uniqifier=3&printMode=true 9/17
11/9/21, 10:09 PM CS PRAC FILE WORK.ipynb - Colaboratory

CS 70 30

-------------------------------------------------------------------------------------

''' WAP (menu driven) using UDF'S TO find a^b  where                            

1. no parameters passed                                      

2. a and b are passed as positional parameters                                      

3. a and b are passed as parameters but b is default parameter with value 3                
4. Exit'''

import random

def power(a,b):

    print(a,'^',b,'=',a**b)

while True:

    print('''Choose one of the following for a^b:-

    1- For undefined a and b(no parameters)

    2- For user defined a and b 

    3- For user defined a but value of b=3

    4- Exit''')

    c=int(input('Enter your choice:- '))

    if c==1:

        a=4

        b=5

        power(a,b)

        

    elif c==2:

        a=int(input('Enter value of base:-'))

        b=int(input('Enter value of exponent:-'))

        power(a,b)

    elif c==3:

        a=int(input('Enter value of base:-'))

        b=3

        print('Value of base is pre defined to 3.')

        power(a,b)

    elif c==4:

        break

Choose one of the following for a^b:-

1- For undefined a and b(no parameters)

2- For user defined a and b

3- For user defined a but value of b=3

4- Exit

Enter your choice:- 1

4 ^ 5 = 1024

Choose one of the following for a^b:-

1- For undefined a and b(no parameters)

2- For user defined a and b

3- For user defined a but value of b=3

4- Exit

Enter your choice:- 2

Enter value of base:-2

Enter value of exponent:-11

2 ^ 11 = 2048

Choose one of the following for a^b:-

https://colab.research.google.com/drive/1jlq4P9j0ZE_nPL-CrcDCzXwyNGF_da_Y#scrollTo=yz1uM6ZSMev1&uniqifier=3&printMode=true 10/17
11/9/21, 10:09 PM CS PRAC FILE WORK.ipynb - Colaboratory

1- For undefined a and b(no parameters)

2- For user defined a and b

3- For user defined a but value of b=3

4- Exit

Enter your choice:- 3

Enter value of base:-11

Value of base is pre defined to 3.

11 ^ 3 = 1331

Choose one of the following for a^b:-

1- For undefined a and b(no parameters)

2- For user defined a and b

3- For user defined a but value of b=3

4- Exit

Enter your choice:- 4

''' wap using udf to calculate area of a triangle using heron's formula showing local and 
import math

a=int(input('enter length of first side of triangle:'))

b=int(input('enter length of second side of triangle:'))
c=int(input('enter length of third side of triangle:'))

def sqrt():

  s= (a+b+c)/2

  x=s*(s-a)*(s-b)*(s-c)

  y=math.sqrt(x)

  print('area of triangle is',y)

sqrt()  

enter length of first side of triangle:32

enter length of second side of triangle:25

enter length of third side of triangle:17

area of triangle is 210.71307505705477

'''WAP to show the implementation of Statistics, Random, Math module'''

import math

print(math.ceil(5.2))

print(math.floor(2.3))

print(math.fabs(-5))

print(math.factorial(6))

print(math.fmod(-15,-2))

print(math.gcd(10,9))

print(math.pow(8,2))

print(math.sqrt(625))

print(math.sin(22))

print(math.cos(22))

print(math.tan(22))

import statistics

print(statistics.mean([6,12,25,36,15,26]))

print(statistics.mode([12,6,12,15,26]))

print(statistics.median([5,2,6,12,25,36,15,26]))

import random

print(random.random())

print(random.randint(2,4))

https://colab.research.google.com/drive/1jlq4P9j0ZE_nPL-CrcDCzXwyNGF_da_Y#scrollTo=yz1uM6ZSMev1&uniqifier=3&printMode=true 11/17
11/9/21, 10:09 PM CS PRAC FILE WORK.ipynb - Colaboratory

print(random.randrange(5))

print(random.randrange(2,6))

5.0

720

-1.0

64.0

25.0

-0.008851309290403876

-0.9999608263946371

0.00885165604168446

20

12

13.5

0.13371824508813956

''' WAP Menu driven using UDFs to perform following tasks-

A) To create a text file named poem.txt in 'write' mode and write four lines of a poem in 
x=open('poem.txt','w')

lines=['johhny JOHHNY yes p@pa\n',

       'EATING sugar no papa\n',

       'telling a LIE no papa1\n',

       'open your mouth #AHAHA\n']

x.writelines(lines)

x.close()

#B) To open it in 'read' mode display contents of the file using read()

x=open('poem.txt','r') 

print(x.read())

x.close()

#C) To open it in 'read' mode display n characters from the file using read(n) where n in 
n=int(input('enter number of characters you want to read:'))

x=open('poem.txt','r')

a=x.read(n)

print(a)

x.close()

#D) To open it in 'read' mode display contents of the file using readline()

x=open('poem.txt','r')

b=x.readline()

print(b)

x.close()

#E)To open it in 'read' mode display contents of the file using readlines()

x=open('poem.txt','r')

print(x.readlines())

x.close()

johhny JOHHNY yes p@pa

EATING sugar no papa

telling a LIE no papa1

open your mouth #AHAHA

https://colab.research.google.com/drive/1jlq4P9j0ZE_nPL-CrcDCzXwyNGF_da_Y#scrollTo=yz1uM6ZSMev1&uniqifier=3&printMode=true 12/17
11/9/21, 10:09 PM CS PRAC FILE WORK.ipynb - Colaboratory

enter number of characters you want to read:15

johhny JOHHNY y

johhny JOHHNY yes p@pa

['johhny JOHHNY yes p@pa\n', 'EATING sugar no papa\n', 'telling a LIE no papa1\n', 'o

'''WAP to read poem.txt and display count of  total characters, vowels, lowercase, upperca
y=open('poem.txt','r')

a=y.read()

count=0

vow=0

low=0

upp=0

spec=0

digi=0

for i in a:

    count+=1

    if i in 'aeiou':

        vow+=1

    elif i in '0123456789':

        digi+=1

    elif i in ' ':

      continue 

    else:

        spec+=1

    if i.isalpha()==True:

        if i.islower()==True:

            low+=1

        else:

            upp+=1

print(count,upp,low,vow,spec,digi)

90 20 50 20 56 1

'''WAP to read poem.txt and write all its lowercase characters in lower.txt, uppercase cha
x=open('poem.txt','r')

y=open('lower.txt','w+')

z=open('upper.txt','w+')

c=open('conso.txt','w+')

e=[]

d=[]

g=[]

f=x.read()

for i in f:

  if i in 'abcdefghijklmnopqrstuvwxyz':

    e.append(i)

    y.writelines(e)

  elif i in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ':

    d.append(i)

    z.writelines(d)

  if  i in 'bcdfghjklmnpqrstvwxyz':

    g.append(i)

https://colab.research.google.com/drive/1jlq4P9j0ZE_nPL-CrcDCzXwyNGF_da_Y#scrollTo=yz1uM6ZSMev1&uniqifier=3&printMode=true 13/17
11/9/21, 10:09 PM CS PRAC FILE WORK.ipynb - Colaboratory

    c.writelines(g)

y.seek(0)

z.seek(0)

c.seek(0)

print('lower case characters ',y.readlines())

print('upper case characters',z.readlines())

print('consonants are ',c.readlines())

x.close()

y.close()

z.close()

c.close()

    

lower case characters ['jjojohjohhjohhnjohhnyjohhnyyjohhnyyejohhnyyesjohhnyyespjohhn


upper case characters ['JJOJOHJOHHJOHHNJOHHNYJOHHNYEJOHHNYEAJOHHNYEATJOHHNYEATIJOHHNY
consonants are ['jjhjhhjhhnjhhnyjhhnyyjhhnyysjhhnyyspjhhnyysppjhhnyysppsjhhnyysppsgj

#WAP to read poem.txt and count frequency of 'the' in it also count and display lines star
x=open('poem.txt','r')

x.readline()

c=0

d=0

for i in x:

    print(i)

    for m in i[0]:

        if m=='A' or m=='a':

            c+=1

            print(x)

        elif m=='T' or m=='t':

            d+=1

            print(x)

print(c,d)

EATING sugar no papa

telling a LIE no papa1

<_io.TextIOWrapper name='poem.txt' mode='r' encoding='UTF-8'>

open your mouth #AHAHA

0 1

''' wap in binary file and perform functions like search, add , update'''

import pickle

def write():

  f=open("Binaryfile.dat",'wb')

  Rec=[]

  while True:

    roll=int(input("ENTER ROLL NO.: "))

    name=input("ENTER NAME OF STUDENT: ")

    marks=int(input("ENTER THE TOTAL MARKS OBTAINED: "))
    grade=input("ENTER THE GRADE: ")

https://colab.research.google.com/drive/1jlq4P9j0ZE_nPL-CrcDCzXwyNGF_da_Y#scrollTo=yz1uM6ZSMev1&uniqifier=3&printMode=true 14/17
11/9/21, 10:09 PM CS PRAC FILE WORK.ipynb - Colaboratory

    R=[roll,name,marks,grade]

    Rec.append(R)

    ch=input("DO YOU WANT INSERT MORE ENTRIES (y/n): ")

    if ch=='n' or ch=='N':

      break

  pickle.dump(Rec,f)

  f.close()

def read():

  f=open("Binaryfile.dat",'rb')

  s=pickle.load(f)

  for i in s:

    r=i[0]

    n=i[1]

    m=i[2]

    g=i[3]

    print(r,n,m,g)

  f.close()

def search():

  f=open("Binaryfile.dat",'rb')

  s=pickle.load(f)

  found=0

  r_no=int(input("Enter roll number to be searched: "))

  for i in s:

    if i[0]==r_no:

      print("RECORD FOUND")

      print(i[0],i[1],i[2],i[3])

      found=1

    if found==0:

      print("RECORD NOT FOUND")

def update():

  f=open("Binaryfile.dat",'rb+')

  s=pickle.load(f)

  found=0

  rno=int(input("ENTER ROLL NO. WHOSE VALUE YOU WANT TO UPDATE: "))

  for i in s:

    if rno==i[0]:

       print("CURRENT VALUE: ", i[1])

       i[1]=input("ENTER NEW NAME:")

       found=1

       break

  if found==0:

    print("RECORD NOT FOUND")

  else:

    f.seek(0)

    pickle.dump(s,f)

  f.close()

write()

read()

search()

update()

read()

ENTER ROLL NO.: 04

ENTER NAME OF STUDENT: Akanksha Sharma

https://colab.research.google.com/drive/1jlq4P9j0ZE_nPL-CrcDCzXwyNGF_da_Y#scrollTo=yz1uM6ZSMev1&uniqifier=3&printMode=true 15/17
11/9/21, 10:09 PM CS PRAC FILE WORK.ipynb - Colaboratory

ENTER THE TOTAL MARKS OBTAINED: 99

ENTER THE GRADE: XII

DO YOU WANT INSERT MORE ENTRIES (y/n): y

ENTER ROLL NO.: 09

ENTER NAME OF STUDENT: Ayushi

ENTER THE TOTAL MARKS OBTAINED: 99

ENTER THE GRADE: XII

DO YOU WANT INSERT MORE ENTRIES (y/n): n

4 Akanksha Sharma 99 XII

9 Ayushi 99 XII

Enter roll number to be searched: 09

RECORD NOT FOUND

RECORD FOUND

9 Ayushi 99 XII

ENTER ROLL NO. WHOSE VALUE YOU WANT TO UPDATE: 04

CURRENT VALUE: Akanksha Sharma

ENTER NEW NAME:ABC

4 ABC 99 XII

9 Ayushi 99 XII

'''WAP to read poem.txt and replace all vowels with '%' display both strings'''
f=open('rhym.txt','w')
lines=['twinkle twinke little star\n',
       'how i wonder what you are\n',
       'up above the world so high\n',
       'like a diamond in the sky\n']
f.writelines(lines)
f.close()
f=open('rhym.txt','r')
y=f.read()
for i in y:
  if i in 'aeiouAEIOU':
    y.replace('i','%')    
f.seek(0)
print(f.read())
f.close()

twinkle twinke little star

how i wonder what you are

up above the world so high

like a diamond in the sky

https://colab.research.google.com/drive/1jlq4P9j0ZE_nPL-CrcDCzXwyNGF_da_Y#scrollTo=yz1uM6ZSMev1&uniqifier=3&printMode=true 16/17
11/9/21, 10:09 PM CS PRAC FILE WORK.ipynb - Colaboratory

https://colab.research.google.com/drive/1jlq4P9j0ZE_nPL-CrcDCzXwyNGF_da_Y#scrollTo=yz1uM6ZSMev1&uniqifier=3&printMode=true 17/17

You might also like