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

Practical FileXII

Uploaded by

renukamal1976
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)
7 views

Practical FileXII

Uploaded by

renukamal1976
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/ 12

BHARTIYA VIDYA MANDIR SR SEC

SCHOOL
UDHAM SINGH NAGAR
Computer Science (083)
Practical File(2024-25)

Submitted By: Submitted

To:

Name: Mrs.

RoomaJoshi

Class:
Section (PGT

COMP.SC)

List Of Python Programs:


1 . Menu based program to find sum, subtraction, multiplication and division of values.

2. Program to print the result depending upon the percentage.

3. Program to print the sum of even numbers from 1 to 20.

4. Program to print the pattern using nested loops.

5. Program using the random functions.

6. Program to print the values of a list in sorted manner.

7. Program to find the minimum value in the list and its index number.

8. Program to find the largest number using user defining function.

9. Program to pass a list as function argument and modify it.

10. Program to write roll no, name and marks of the students in a data file Marks.dat.

11. Program to display rollno , name and marks of the students in a data file Marks.dat.

12. Program to write data , read and display in and from text file ‘test3.txt’.

13. Program to read and display those lines from file that start with alphabet ‘W’.

14. Program to read and display those lines from file that end with alphabet ‘g’.

15. Program to write data , read and display in and from a csv file ‘student.csv’.
Python Programs
1 . Menu based program to find sum, subtraction, multiplication and division of values.

print("1. Sum of two numbers")


print("2. Subtaction of two numbers")
print("3. Multiplication of two numbers")
print("4. Division of two numbers")
choice=int(input('Enter your choice'))
if choice==1 :
a=int(input('Enter first number'))
b=int(input('Enter second number'))
c=a+b
print("Sum=",c)
elif choice==2 :
a=int(input('Enter first number'))
b=int(input('Enter second number'))
c=a-b
print("Subtraction=",c)
elif choice==3 :
a=int(input('Enter first number'))
b=int(input('Enter second number'))
c=a*b
print("Multiplication=",c)
elif choice==4 :
a=int(input('Enter first number'))
b=int(input('Enter second number'))
c=a/b
print("Division=",c)
else :
print("Wrong choice")
2. Program to print the result depending upon the percentage :

per=int(input('Enter your percentage'))


if per>= 33 :
print("Pass");
elif per>=20 and per<33 :
print("compartment");
else:
print("Fail");

3. Program to print the sum of even numbers from 1 to 20 :

sum=0
for num in range(21):
if num%2==0:
sum=sum+num
print("Sum of even values=",sum)

4. Program to print the pattern using nested loops :

for i in range(1,6):
print()
for j in range(1,i+1):
print ('*',end="")

5. Program using the random functions.

import random
AR="HELLO WORLD";
FROM=random.randint(1,3)
for K in range(0, FROM):
print (AR[K],end="#")

6. Program to print the values of a list in sorted manner :


aList=[20 , 10 , 30 , 50]
print("Original List",aList)
n=len(aList)
for i in range(n-1):
for j in range(0,n-i-1):
ifaList[j]>aList[j+1]:
aList[j],aList[j+1]=aList[j+1],aList[j]
print("Sorted List",aList)

7. Program to find the minimum value in the list and its index number :
L=eval(input('Enter list values'))
length=len(L) #length=6
min=L[0] #min=10
loc=0
for i in range(length): #0,1,2,3,4,5
if L[i]<min:
min=L[i] #min=1
loc=i
print("Minimum value=",min)
print("Location=",loc)

8. Program to find the largest number using user defining function :

def largest():
a=int(input("Enter first number="))
b=int(input("Enter second number="))
if a>b :
print ("Largest value= ", a)
else:
print ("Largest value=" , b)
return
largest()

9. Program to pass a list as function argument and modify it:

defchangeme( mylist ):
print ("inside the function before change ", mylist)
mylist[0]=1000
print ("inside the function after change ", mylist)
return

list1 = [10,20,30]
print ("outside function before calling function", list1)
changeme( list1 )
print ("outside function after calling function", list1)

10. Program to write rollno , name and marks of the students in a datafile Marks.dat.:

count=int(input('How many students are there in the class'))


fileout=open("Marks.dat","a")
for i in range(count):
print("Enter details of student",(i+1),"below")
rollno=int(input("Enter rollno:"))
name=input("name")
marks=float(input('marks'))
rec=str(rollno)+","+name+","+str(marks)+"\n"
fileout.write(rec)
fileout.close()
11. Program to display rollno , name and marks of the students in a datafile Marks.dat. :

fileinp=open("Marks.dat","r")
whilestr:
str=fileinp.readline()
print(str)
fileinp.close()

12. Program to write data , read and display in and from text file ‘test3.txt’.

fh=open("test3.txt","w")
fh.write("We are writing \n")
fh.write("data \n")
fh.write("to a text file \n")
print("Data Written\n \n")
fh.close()

fh=open("test3.txt","r")
lines=fh.readlines()
print("Reading and displaying from text fom file\n")
for line in lines:
print(line,end='')
fh.close()

13. Program to read and display those lines from file that start with alphabet ‘W’.

file1=open("test3.txt","r")
count=0
str1=file1.readlines()
print(str1)
for i in str1:
if i[0]=='W':
print (i)
file1.close()

14. Program to read and display those lines from file that end with alphabet ‘g’.

file1=open("test3.txt","r")
count=0
str1=file1.readlines()
for i in str1:
if i[-3]=='g':
count+=1
print("Number of lines which end with 'g'=",count)

file1.close()

15. Program to write data , read and display in and from a csv file ‘student.csv’.

import csv
fh=open("student.csv","w")
stuwriter=csv.writer(fh)
stuwriter.writerow([1,'aman',50])
stuwriter.writerow([2,'Raman',60])
print("Data Entered\n \n")
fh.close()

import csv
fh=open("student.csv","r")
stureader=csv.reader(fh)
print("Data Displayed:")
for rec in stureader:
print(rec)
fh.close()

You might also like