0% found this document useful (0 votes)
17 views34 pages

File Organisation

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)
17 views34 pages

File Organisation

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/ 34

FILE ORGANISATION ASSIGNMENT - 1

CODES...

# Creating a file with name file.txt...

def create():

f=open('file.txt','w')

n=int(input("Enter no. of lines to be entered : "))

for i in range(n):

s=input("Enter line : ")

f.write(s+'\n')

f.close()

print("A file is created with name File.txt")

create()

# To find the size of file...

def size():

f=open('file.txt','r')

s=f.read()

print("size of file : ",len(s))

f.close()
# To find no. of lines in files...

def num():

f=open('file.txt','r')

s=f.readlines()

print("Number of lines : ",len(s))

f.close()

# To print every line...

def line():

f=open('file.txt','r')

s=f.readlines()

for i in s:

print(i)

f.close()

# To print and find the no. of words...

def words():

f=open('file.txt','r')

s=f.read()

d=s.split()

c=0
for i in d:

print(i)

c+=1

print("Total no. of words : " ,c)

f.close()

# To print the no. of vowels in the file...

def vowels():

f=open('file.txt','r')

s=f.read()

c=0

for i in s:

if i in 'AEIOUaeiou':

c+=1

print("Number of vowels : ",c)

f.close()

# To print the no. of consonants...

def consonant():

f=open("file.txt")

s=f.read()

c=0

for i in s:
if i.isalpha():

if i not in "AEIOUaeiou":

c+=1

print("Number of consonants : ",c)

f.close()

# To find the no. of digits...

def digits():

f=open('file.txt','r')

s=f.read()

c=0

for i in s:

if i.isdigit():

c+=1

print("Number of digits : ",c)

f.close()

# To find the no. of alphabets...

def alphabets():

f=open("file.txt",'r')

s=f.read()

c=0

for i in s:

if i.isalpha():
c+=1

print("Number of Alphabets : ",c)

f.close()

# To find the no. of lowercase Alphabets...

def lcase():

f=open('file.txt','r')

s=f.read()

c=0

for i in s:

if i.isalpha():

if i.islower():

c+=1

print("Number of lowercase alphabets : ",c)

f.close()

# To display first line of file...

def first():

f=open('file.txt','r')

s=f.readlines()

print("First line : ",s[0])

f.close()
# To print last line of file...

def last():

f=open('file.txt','r')

s=f.readlines()

print("Last line : ",s[-1])

f.close()

# To print Every line sarting with digit...

def dig():

f=open('file.txt','r')

s=f.readlines()

for i in s:

if i[0].isdigit():

print(i)

else:

print("There isn't any digit")

break

f.close()

# To print no. of 'This'...


def this():

f=open('file.txt','r')

s=f.read()

c=0

for i in s.split():

if i=='This':

c+=1

print('Total Number of "This" : ',c)

f.close()

# To print alphanumericals of the file...

def alnum():

f=open('file.txt','r')

s=f.read()

for i in s:

if i.isalnum():

print(i)

f.close()

# To print every line not starting with a digit...

def display():

f=open('file.txt','r')
s=f.readlines()

for i in s:

if i[0].isdigit():

continue

else:

print(i)

f.close()

# To copy the whole file content on another file...

def copy():

f=open('file.txt','r')

f1=open('info.txt','w')

s=f.readlines()

for i in s:

f1.write(i)

print("Content copied successfully")

f1.close()

f.close()

# To Capitalize First letter of every line...

def capitalize():

f=open('file.txt','r')

s=f.readlines()

for i in s:
i=i.title()

print(i)

f.close()

# To display every line not starting with 'P','p'...

def start():

f=open('file.txt','r')

s=f.readlines()

for i in s:

if i[0]not in 'pP':

print(i)

f.close()

# Total no. of lines starting with 'S' or 's'...

def starting():

f=open('file.txt','r')

s=f.readlines()

c=0

for i in s:

if i[0] in 'sS':

print(i)

c+=1
print("Total numbers of required lines : ",c)

f.close()

# MENU...

while True:

print("""what do you want to perform?

1.Display the size of the file

2.Display no. of lines

3.Display every line

4.Display and find no. of words

5.Display no. of vowels in the file

6.Display no. of consonants in he file

7.Display no. of digits

8.Display no. of alphabets

9.Display no. of lowercase alphabets

10.Display first line of the file

11.Display last line of the file

12.Display line starting with digit

13.Display number of 'This' in the file

14.Check and display alphanumerics of file

15.Display all the lines which do not start with a digit

16.Copy the content of this file into Info.txt

17.Capitalize the first letter of every line

18.Display the line not starting with 'P' or 'p'

19.Find total no. of lines starting with 'S' or 's'""")


a=int(input("Enter your option : "))

if a==1:

size()

elif a==2:

num()

elif a==3:

line()

elif a==4:

words()

elif a==5:

vowels()

elif a==6:

consonant()

elif a==7:

digits()

elif a==8:

alphabets()

elif a==9:

lcase()

elif a==10:

first()

elif a==11:

last()

elif a==12:

dig()
elif a==13:

this()

elif a==14:

alnum()

elif a==15:

display()

elif a==16:

copy()

elif a==17:

capitalize()

elif a==18:

start()

elif a==19:

starting()

else:

print("invalid value given")

break

restart=input("Do you want to perform again? (y/n) : ")

if restart=='y':

pass

elif restart=='n':

break

else:

print("value unacceptable")

print("exiting")
break

OUTPUTS...

Python 3.12.4 (tags/v3.12.4:8e8a4ba, Jun 6 2024, 19:30:16) [MSC v.1940 64 bit (AMD64)]
on win32

Type "help", "copyright", "credits" or "license()" for more information.

= RESTART: C:\Users\dixit\AppData\Local\Programs\Python\Python312\file.py

Enter no. of lines to be entered : 5

Enter line : Python is a high level programing language.

Enter line : it was created by Guido Van Rossum.

Enter line : 1991 was the year when it was released.

Enter line : python has dynamic typing and automatic memory management.

Enter line : some features of python are interpreted language, portability and readability.

A file is created with name File.txt

what do you want to perform?

1.Display the size of the file

2.Display no. of lines

3.Display every line

4.Display and find no. of words


5.Display no. of vowels in the file

6.Display no. of consonants in he file

7.Display no. of digits

8.Display no. of alphabets

9.Display no. of lowercase alphabets

10.Display first line of the file

11.Display last line of the file

12.Display line starting with digit

13.Display number of 'This' in the file

14.Check and display alphanumerics of file

15.Display all the lines which do not start with a digit

16.Copy the content of this file into Info.txt

17.Capitalize the first letter of every line

18.Display the line not starting with 'P' or 'p'

19.Find total no. of lines starting with 'S' or 's'

Enter your option : 1

size of file : 258

Do you want to perform again? (y/n) : y

what do you want to perform?

1.Display the size of the file

2.Display no. of lines

3.Display every line

4.Display and find no. of words

5.Display no. of vowels in the file

6.Display no. of consonants in he file

7.Display no. of digits


8.Display no. of alphabets

9.Display no. of lowercase alphabets

10.Display first line of the file

11.Display last line of the file

12.Display line starting with digit

13.Display number of 'This' in the file

14.Check and display alphanumerics of file

15.Display all the lines which do not start with a digit

16.Copy the content of this file into Info.txt

17.Capitalize the first letter of every line

18.Display the line not starting with 'P' or 'p'

19.Find total no. of lines starting with 'S' or 's'

Enter your option : 2

Number of lines : 5

Do you want to perform again? (y/n) : y

what do you want to perform?

1.Display the size of the file

2.Display no. of lines

3.Display every line

4.Display and find no. of words

5.Display no. of vowels in the file

6.Display no. of consonants in he file

7.Display no. of digits

8.Display no. of alphabets

9.Display no. of lowercase alphabets

10.Display first line of the file


11.Display last line of the file

12.Display line starting with digit

13.Display number of 'This' in the file

14.Check and display alphanumerics of file

15.Display all the lines which do not start with a digit

16.Copy the content of this file into Info.txt

17.Capitalize the first letter of every line

18.Display the line not starting with 'P' or 'p'

19.Find total no. of lines starting with 'S' or 's'

Enter your option : 3

Python is a high level programing language.

it was created by Guido Van Rossum.

1991 was the year when it was released.

python has dynamic typing and automatic memory management.

some features of python are interpreted language, portability and readability.

Do you want to perform again? (y/n) : y

what do you want to perform?

1.Display the size of the file

2.Display no. of lines

3.Display every line

4.Display and find no. of words


5.Display no. of vowels in the file

6.Display no. of consonants in he file

7.Display no. of digits

8.Display no. of alphabets

9.Display no. of lowercase alphabets

10.Display first line of the file

11.Display last line of the file

12.Display line starting with digit

13.Display number of 'This' in the file

14.Check and display alphanumerics of file

15.Display all the lines which do not start with a digit

16.Copy the content of this file into Info.txt

17.Capitalize the first letter of every line

18.Display the line not starting with 'P' or 'p'

19.Find total no. of lines starting with 'S' or 's'

Enter your option : 4

Python

is

high

level

programing

language.

it

was

created
by

Guido

Van

Rossum.

1991

was

the

year

when

it

was

released.

python

has

dynamic

typing

and

automatic

memory

management.

some

features

of

python

are

interpreted
language,

portability

and

readability.

Total no. of words : 40

Do you want to perform again? (y/n) : y

what do you want to perform?

1.Display the size of the file

2.Display no. of lines

3.Display every line

4.Display and find no. of words

5.Display no. of vowels in the file

6.Display no. of consonants in he file

7.Display no. of digits

8.Display no. of alphabets

9.Display no. of lowercase alphabets

10.Display first line of the file

11.Display last line of the file

12.Display line starting with digit

13.Display number of 'This' in the file

14.Check and display alphanumerics of file

15.Display all the lines which do not start with a digit

16.Copy the content of this file into Info.txt

17.Capitalize the first letter of every line

18.Display the line not starting with 'P' or 'p'

19.Find total no. of lines starting with 'S' or 's'


Enter your option : 5

Number of vowels : 80

Do you want to perform again? (y/n) : y

what do you want to perform?

1.Display the size of the file

2.Display no. of lines

3.Display every line

4.Display and find no. of words

5.Display no. of vowels in the file

6.Display no. of consonants in he file

7.Display no. of digits

8.Display no. of alphabets

9.Display no. of lowercase alphabets

10.Display first line of the file

11.Display last line of the file

12.Display line starting with digit

13.Display number of 'This' in the file

14.Check and display alphanumerics of file

15.Display all the lines which do not start with a digit

16.Copy the content of this file into Info.txt

17.Capitalize the first letter of every line

18.Display the line not starting with 'P' or 'p'

19.Find total no. of lines starting with 'S' or 's'

Enter your option : 6

Number of consonants : 128

Do you want to perform again? (y/n) : y


what do you want to perform?

1.Display the size of the file

2.Display no. of lines

3.Display every line

4.Display and find no. of words

5.Display no. of vowels in the file

6.Display no. of consonants in he file

7.Display no. of digits

8.Display no. of alphabets

9.Display no. of lowercase alphabets

10.Display first line of the file

11.Display last line of the file

12.Display line starting with digit

13.Display number of 'This' in the file

14.Check and display alphanumerics of file

15.Display all the lines which do not start with a digit

16.Copy the content of this file into Info.txt

17.Capitalize the first letter of every line

18.Display the line not starting with 'P' or 'p'

19.Find total no. of lines starting with 'S' or 's'

Enter your option : 7

Number of digits : 4

Do you want to perform again? (y/n) : y

what do you want to perform?

1.Display the size of the file

2.Display no. of lines


3.Display every line

4.Display and find no. of words

5.Display no. of vowels in the file

6.Display no. of consonants in he file

7.Display no. of digits

8.Display no. of alphabets

9.Display no. of lowercase alphabets

10.Display first line of the file

11.Display last line of the file

12.Display line starting with digit

13.Display number of 'This' in the file

14.Check and display alphanumerics of file

15.Display all the lines which do not start with a digit

16.Copy the content of this file into Info.txt

17.Capitalize the first letter of every line

18.Display the line not starting with 'P' or 'p'

19.Find total no. of lines starting with 'S' or 's'

Enter your option : 8

Number of Alphabets : 208

Do you want to perform again? (y/n) : y

what do you want to perform?

1.Display the size of the file

2.Display no. of lines

3.Display every line

4.Display and find no. of words

5.Display no. of vowels in the file


6.Display no. of consonants in he file

7.Display no. of digits

8.Display no. of alphabets

9.Display no. of lowercase alphabets

10.Display first line of the file

11.Display last line of the file

12.Display line starting with digit

13.Display number of 'This' in the file

14.Check and display alphanumerics of file

15.Display all the lines which do not start with a digit

16.Copy the content of this file into Info.txt

17.Capitalize the first letter of every line

18.Display the line not starting with 'P' or 'p'

19.Find total no. of lines starting with 'S' or 's'

Enter your option : 9

Number of lowercase alphabets : 204

Do you want to perform again? (y/n) : y

what do you want to perform?

1.Display the size of the file

2.Display no. of lines

3.Display every line

4.Display and find no. of words

5.Display no. of vowels in the file

6.Display no. of consonants in he file

7.Display no. of digits

8.Display no. of alphabets


9.Display no. of lowercase alphabets

10.Display first line of the file

11.Display last line of the file

12.Display line starting with digit

13.Display number of 'This' in the file

14.Check and display alphanumerics of file

15.Display all the lines which do not start with a digit

16.Copy the content of this file into Info.txt

17.Capitalize the first letter of every line

18.Display the line not starting with 'P' or 'p'

19.Find total no. of lines starting with 'S' or 's'

Enter your option : 10

First line : Python is a high level programing language.

Do you want to perform again? (y/n) : y

what do you want to perform?

1.Display the size of the file

2.Display no. of lines

3.Display every line

4.Display and find no. of words

5.Display no. of vowels in the file

6.Display no. of consonants in he file

7.Display no. of digits

8.Display no. of alphabets

9.Display no. of lowercase alphabets

10.Display first line of the file


11.Display last line of the file

12.Display line starting with digit

13.Display number of 'This' in the file

14.Check and display alphanumerics of file

15.Display all the lines which do not start with a digit

16.Copy the content of this file into Info.txt

17.Capitalize the first letter of every line

18.Display the line not starting with 'P' or 'p'

19.Find total no. of lines starting with 'S' or 's'

Enter your option : 11

Last line : some features of python are interpreted language, portability and readability.

Do you want to perform again? (y/n) : y

what do you want to perform?

1.Display the size of the file

2.Display no. of lines

3.Display every line

4.Display and find no. of words

5.Display no. of vowels in the file

6.Display no. of consonants in he file

7.Display no. of digits

8.Display no. of alphabets

9.Display no. of lowercase alphabets

10.Display first line of the file

11.Display last line of the file

12.Display line starting with digit


13.Display number of 'This' in the file

14.Check and display alphanumerics of file

15.Display all the lines which do not start with a digit

16.Copy the content of this file into Info.txt

17.Capitalize the first letter of every line

18.Display the line not starting with 'P' or 'p'

19.Find total no. of lines starting with 'S' or 's'

Enter your option : 12

There isn't any digit

Do you want to perform again? (y/n) : y

what do you want to perform?

1.Display the size of the file

2.Display no. of lines

3.Display every line

4.Display and find no. of words

5.Display no. of vowels in the file

6.Display no. of consonants in he file

7.Display no. of digits

8.Display no. of alphabets

9.Display no. of lowercase alphabets

10.Display first line of the file

11.Display last line of the file

12.Display line starting with digit

13.Display number of 'This' in the file

14.Check and display alphanumerics of file

15.Display all the lines which do not start with a digit


16.Copy the content of this file into Info.txt

17.Capitalize the first letter of every line

18.Display the line not starting with 'P' or 'p'

19.Find total no. of lines starting with 'S' or 's'

Enter your option : 13

Total Number of "This" : 0

Do you want to perform again? (y/n) : y

what do you want to perform?

1.Display the size of the file

2.Display no. of lines

3.Display every line

4.Display and find no. of words

5.Display no. of vowels in the file

6.Display no. of consonants in he file

7.Display no. of digits

8.Display no. of alphabets

9.Display no. of lowercase alphabets

10.Display first line of the file

11.Display last line of the file

12.Display line starting with digit

13.Display number of 'This' in the file

14.Check and display alphanumerics of file

15.Display all the lines which do not start with a digit

16.Copy the content of this file into Info.txt

17.Capitalize the first letter of every line

18.Display the line not starting with 'P' or 'p'


19.Find total no. of lines starting with 'S' or 's'

Enter your option : 14

P,y,t,h,o,n,i,s,a,h,i,g,h,l,e,v,e,l,p,r,o,g,r,a,m,i,n,g,l,a,n,g,u,a,g,e,i,t,w,a,s,c,r,e,a,t,e,d,b,y,G,
u,i,d,o,V,a,n,R,o,s,s,u,m,1,9,9,1,w,a,s,t,h,e,y,e,a,r,w,h,e,n,i,t,w,a,s,r,e,l,e,a,s,e,d,p,y,t,h,o
,n,h,a,s,d,y,n,a,m,i,c,t,y,p,i,n,g,a,n,d,a,u,t,o,m,a,t,i,c,m,e,m,o,r,y,m,a,n,a,g,e,m,e,n,t,s,o,
m,e,f,e,a,t,u,r,e,s,o,f,p,y,t,h,o,n,a,r,e,i,n,t,e,r,p,r,e,t,e,d,l,a,n,g,u,a,g,e,p,o,r,t,a,b,i,l,i,t,y,a,
n,d,r,e,a,d,a,b,i,l,i,t,y,Do you want to perform again? (y/n) : y

what do you want to perform?

1.Display the size of the file

2.Display no. of lines

3.Display every line

4.Display and find no. of words

5.Display no. of vowels in the file

6.Display no. of consonants in he file

7.Display no. of digits

8.Display no. of alphabets

9.Display no. of lowercase alphabets

10.Display first line of the file

11.Display last line of the file

12.Display line starting with digit

13.Display number of 'This' in the file

14.Check and display alphanumerics of file

15.Display all the lines which do not start with a digit

16.Copy the content of this file into Info.txt

17.Capitalize the first letter of every line

18.Display the line not starting with 'P' or 'p'

19.Find total no. of lines starting with 'S' or 's'


Enter your option : 15

Python is a high level programing language.

it was created by Guido Van Rossum.

python has dynamic typing and automatic memory management.

some features of python are interpreted language, portability and readability.

Do you want to perform again? (y/n) : y

what do you want to perform?

1.Display the size of the file

2.Display no. of lines

3.Display every line

4.Display and find no. of words

5.Display no. of vowels in the file

6.Display no. of consonants in he file

7.Display no. of digits

8.Display no. of alphabets

9.Display no. of lowercase alphabets

10.Display first line of the file

11.Display last line of the file

12.Display line starting with digit

13.Display number of 'This' in the file

14.Check and display alphanumerics of file

15.Display all the lines which do not start with a digit


16.Copy the content of this file into Info.txt

17.Capitalize the first letter of every line

18.Display the line not starting with 'P' or 'p'

19.Find total no. of lines starting with 'S' or 's'

Enter your option : 16

Content copied successfully

Do you want to perform again? (y/n) : y

what do you want to perform?

1.Display the size of the file

2.Display no. of lines

3.Display every line

4.Display and find no. of words

5.Display no. of vowels in the file

6.Display no. of consonants in he file

7.Display no. of digits

8.Display no. of alphabets

9.Display no. of lowercase alphabets

10.Display first line of the file

11.Display last line of the file

12.Display line starting with digit

13.Display number of 'This' in the file

14.Check and display alphanumerics of file

15.Display all the lines which do not start with a digit

16.Copy the content of this file into Info.txt

17.Capitalize the first letter of every line

18.Display the line not starting with 'P' or 'p'


19.Find total no. of lines starting with 'S' or 's'

Enter your option : 17

Python is a high level programing language.

It was created by Guido Van Rossum.

1991 was the year when it was released.

Python has dynamic typing and automatic memory management.

Some features of python are interpreted language, portability and readability.

Do you want to perform again? (y/n) : y

what do you want to perform?

1.Display the size of the file

2.Display no. of lines

3.Display every line

4.Display and find no. of words

5.Display no. of vowels in the file

6.Display no. of consonants in he file

7.Display no. of digits

8.Display no. of alphabets

9.Display no. of lowercase alphabets

10.Display first line of the file

11.Display last line of the file

12.Display line starting with digit


13.Display number of 'This' in the file

14.Check and display alphanumerics of file

15.Display all the lines which do not start with a digit

16.Copy the content of this file into Info.txt

17.Capitalize the first letter of every line

18.Display the line not starting with 'P' or 'p'

19.Find total no. of lines starting with 'S' or 's'

Enter your option : 18

it was created by Guido Van Rossum.

1991 was the year when it was released.

some features of python are interpreted language, portability and readability.

Do you want to perform again? (y/n) : y

what do you want to perform?

1.Display the size of the file

2.Display no. of lines

3.Display every line

4.Display and find no. of words

5.Display no. of vowels in the file

6.Display no. of consonants in he file

7.Display no. of digits

8.Display no. of alphabets

9.Display no. of lowercase alphabets

10.Display first line of the file


11.Display last line of the file

12.Display line starting with digit

13.Display number of 'This' in the file

14.Check and display alphanumerics of file

15.Display all the lines which do not start with a digit

16.Copy the content of this file into Info.txt

17.Capitalize the first letter of every line

18.Display the line not starting with 'P' or 'p'

19.Find total no. of lines starting with 'S' or 's'

Enter your option : 19

some features of python are interpreted language, portability and readability.

Total numbers of required lines : 1

Do you want to perform again? (y/n) : n

ANSHIKA DIXIT
CLASS= XII-B

ROLL NO.=11

You might also like