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

Python Proj

Uploaded by

Aman Hashim
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)
5 views

Python Proj

Uploaded by

Aman Hashim
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/ 19

MES RAJA RESIDENTIAL

SCHOOL
CALICUT, N. I. T.

LABORATORY RECORD
COMPUTER SCIENCE

Name: C.K. Shaiban Abdu Razak Class: XII-B


MES RAJA RESIDENTIAL
SCHOOL
CALICUT, N. I. T.

LABORATORY RECORD
COMPUTER SCIENCE

Name: C.K. Shaiban Abdu Razak

Class : XII-B Year: 2020-21

Admission No: 8848 Reg. No:

Principal Teacher in charge


Place:
Date: External Examiner

Contents
SI. No Date Programs Page No. Signature

1 FIBONACCI SERIES

2 LIST - NUMBERS

3 DICTIONARY - STUDENTS
4 FUNCTION - PERFECT NUMBER
5 FUNCTION - PRIME NUMBER
TEXT FILE – NUMBER OF VOWELS, CONSONANTS,
6
UPPER AND LOWER CHARACTERS.
7 TEXT FILE – WORDS SEPERATED BY #
8 TUPLE – FRUITS
9 STRING – PALINDROME
10 BINARY FILE – SEARCH
11 BINARY FILE – MODIFY
12 BINARY FILE – DELETE
13
14
15
16
17
18
19
20
Program No: 1 Date:

FIBONACCI SERIES

AIM

Write a program to print Fibonacci series upto a certain limit.

PROGRAM

n = int(input(“Enter the limit:”))


a=0
b=1
c=1
print(“Fibonacci series:\n”)
print(a, b, end = “\t”)
while(c <= n):
print(c, end = “,”)
a=b
b=c
c=a+b

OUTPUT

Enter the limit: 15

Fibonacci series:
0 1 1 2 3 5 8 13
Program No. 2 Date:

LIST-NUMBERS

AIM
Write a program to enter 'n' elements to a list at runtime. Then display
the following:
 List in ascending order
 List in descending order.
 The largest element in the list

PROGRAM

lim = int(input("Enter the limit:")


l = []
for x in range(lim):
nl = int(input("Enter the number:")
l.append(nl)
print("The list is", l)
l.sort()
print("The list in ascending order is:", l)
l.sort(reverse = True)
print("The list in descending order is:", l)
print("The largest element in the list is:", max(l))
print("The smallest element in the list is:", min(l))

OUTPUT

Enter the limit: 2


Enter a number: 2
The list is [1, 2]
The list in ascending order is: [1, 2]
The list in ascending order is: [2, 1]
The largest element in the list is: 2
Program No. 3 Date:

DICTIONARY-STUDENTS
AIM

Write a program to input 'n' admission number and names to store in a


dictionary and search a particular student based on the admission

PROGRAM

d = dict()
n = int(input("Enter the total number of students:"))
for x in range(n):
adm = int(input("Enter the admission no.:"))
nm = input("Enter the name:")
d[adm] = nm
sadm = int(input("Enter the admission number to search:"))
k = d.keys()
for x in k:
if sadm == x:
print("Admission no. =", x, "\t|\tName =", d[x])
break
else:
print("Student not found!")

OUTPUT

Enter the total number of students: 2


Enter the admission no.: 8848
Enter the name: Shaiban
Enter the admission no.: 8784
Enter the name: Nihal
Enter the admission number to search: 8848
Admission no. = 8848 | Name = Shaiban
Program No. 4 Date:

FUNCTION - PERFECT NUMBER


AIM

Write a program using function to check a number is perfect or not.

PROGRAM

def perfect(no):
sum = 0
for i in range(1, no):
if no % i == 0:
sum += i
if sum == no:
print(„The given number is a Perfect Number‟)
else:
print(„The given number is not a perfect number')
no = int(input("Enter a number: "))
perfect(no)

OUTPUT

1.
Enter a number: 496
The given number is a Perfect Number

2.
Enter a number: 528
The given number is not a Perfect Number
Program No. 5 Date:

FUNCTION - PRIME NUMBERS


AIM

Write a program to display all the prime numbers up to a limit using function.

PROGRAM

def prime(no):
for x in range(2, no):
if no % x == 0:
break
else:
print(no, end =„,\t‟)
li = int(input("Enter a limit:"))
print("The prime numbers are:")
for x in range(2, li+ 1):
prime(x)

OUTPUT

Enter a limit: 15
The prime numbers are:
2, 3, 5, 7, 11, 13
Program No. 6 Date:
TEXT FILE-NUMBER OF VOWELS, CONSONANTS,
UPPERCASE AND LOWERCASE CHARACTERS
AIM

Write a program to write multiple lines to a text file "student.txt" and then read the file
and display the number of vowels, consonants, uppercase and lowercase characters in the
file.

PROGRAM

def writedata():
f = open("student.txt","w")
ans = „y'
while ans.lower() = „y‟:
str-input("Enter the data to write to the file:")
f.write(str+"\n')
ans = input("Do you want to write more(y,n)?")
f.close()
def readdata():
f = open("student.txt", "r")
str-f.read()
vow=0
con=0
up-0
low=0
for x in str:
if x.upper() in 'AEIOU':
vow += l
if x.upper() in 'BCDFGHJKLMNPQRSTVWXYZ‟
con += l
if x.isupper():
up += 1
if x.islower():
low += 1
print("Number of vowels = ", vow)
print("Number of consonents = ", con)
print("Number of lower case letters = ", low)
print("Number of upper case letters = ", up)
f.close()
OUTPUT

Enter the data to write to the file: I am python


Do you want to write more(y.n)? n
Number of vowels = 3
Number of consonants = 6
Program No. 7 Date:

AIM

Write a program to write multiple lines to a text file"student.txt" and


then read the file line by line and display each word separated by a #.

PROGRAM

def writedata():
f = open("student.txt","w")
ans = „y‟
while ans.lower() == „y‟:
str = input("Enter the data to write to the file:")
f.write(str + „\n‟)
ans = input("Do you want to write more(y,n)?")
f.close()
def readdata():
f = open("student.txt","r")
print("The formatted data is")
for line in f:
wd = line.split()
for y in wd:
print(y. end=„#‟)
print()
f.close()
writedata()

OUTPUT

Enter the data to write to the file: I am Python


Do you want to write more(y,n)? n
The formatted data is
I#am#Python#
Program No. 8 Date:

TUPLE - FRUITS
AIM

Write a program to enter 'n' fruit names to a tuple at runtime. Then check if a given
fruit is present in the tuple and if present, display its position, else display "Fruit not
found".

PROGRAM

n = int(input("Enter the limit:"))


t = tuple() for x
in range(n):
el = input("Enter a Fruit name:")
t = t + (el)
print("The tuple is", t)
sr = input("Enter the fruit to search:")
if sr in t:
indx = t.index(sr)
print("The fruit found at the location", indx + 1)
else:
print("Fruit not found")

OUTPUT

Enter the limit: 3


Enter a Fruit name: Apple
Enter a Fruit name: Mango
Enter a Fruit name: Orange
The tuple is („Apple‟, „Mango‟, „Orange‟)
Enter the fruit to search: Orange
The fruit found at the location: 3
Program No. 9 Date:

STRING-PALINDROME
AIM

Write a program to check whether the string is a palindrome or not.

PROGRAM

s = input("Enter a string:")
l = len(s)
p= l - 1
indx = 0
while(indx < p):
if(s[p] == str[indx]):
indx = indx+1
p = p -1;
else:
print("The given string is not a Palindrome")
break
else:
print(s, " is a Palindrome")

OUTPUT

Enter a string: noon


noon is a Palindrome
Program No. 10 Date:

BINARY FILE - SEARCH


AIM

Write a program to create a binary file student.dat with some student


details(Name & roll no.). Search for a given roll number and if found, display
the name, else display an appropriate message.

PROGRAM

def entry():
st = []
n = int(input("Enter the limit: "))
for x in range(n):
rl = int(input("Enter the roll no.: "))
nm = input("Enter the name: ")
st.append([rl, nm])
import pickle
f = open("student.dat","wb")
pickle.dump(st, f)
f.close()
def search():
import pickle
f = open("student.dat","rb")
st.pickle.load(f)
print("The data in student.dat is")
for x in st:
print(x)
s = int(input("Enter the student roll number to for x in st: search"))
for x in st:
if s == x[0]:
print("Record found.\n")
print("Name:",x[| ])
break
else:
print("\nStudent record not found!")
f.close()
entry()
search()
OUTPUT

Enter the limit: 2


Enter the roll number: 1
Enter the name: Shaiban
Enter the roll number: 2
Enter the name: Fiam
The data in student.dat is:
[1. „Shaiban‟]
[2. „Fiam‟]
Enter the student roll number to search: 2
Record found.
Name: Fiam
Program No. 11 Date:

BINARY FILE - REMOVE


AIM

Write a program to create a binary file "student.dat" with some student


details(Roll number and name).Then modify the name of a student corresponding to a
particular roll number.

PROGRAM

def entry():
st = []
lim = int(input("Enter the limit: "))
for x in range(lim):
rl = int(input("Enter the roll number:"))
nm = input("Enter the name: ")
st.append([rl,nm])
import pickle
f = open("student.dat","wb")
pickle.dump(st, f)
f.close()
def display():
import pickle
f = open("student.dat","rb")
st = pickle.load(f)
for x in st:
print(x)
f.close()
def modify():
import pickle
f = open("student.dat","rb")
print("The data in student.dat is")
display()
temp = []
st = pickle.load(f)
f.close()
s = int(input("\n\nEnter the roll number of the student whose name to modify: "))
for x in st:
if s == x[0]:
nm = input("Enter the new name: ")
x[1] = nm
temp.append(x)
f = open("student.dat", "wb")
pickle.dump(temp, f)
f.close()
print("\n\nThe updated file is: ")
display()
entry()
modify()

OUTPUT

Enter the limit: 3


Enter the roll number: 1
Enter the name: Shaiban
Enter the roll number: 2
Enter the name: Fiam
Enter the roll number: 3
Enter the name: Nihal
The data in student.dat is
[1, 'Shaiban']
[2. 'Fiam']
[3. 'Nihal']

Enter the roll number of the student whose name to modify: 2


Enter the new name: Masroor

The updated file is:


[1. „Shaiban‟]
[2. „Masroor‟]
[3. „Nihal‟]
Program No. 12 Date:

BINARY FILE - DELETE


AIM
Write a program to create a binary file student.dat with some students details(Roll
number and name).Then remove a particular student from the

PROGRAM

def entry():
st = []
lim = int(input("Enter the limit: "))
for x in range(lim):
rl = int(input("Enter the roll number: "))
nm = input("Enter the name: ")
st.append([rl.nm])
import pickle
f = open("student.dat","wb")
pickle.dump(st, f)
f.close()
def display():
import pickle
fopen("student.dat","rb")
st-pickle.load(f)
for x in st:
print(x)
f.close()
def delete()
import pickle
f = open("student.dat","rb")
print("The data in student.dat is: ")
display()
temp = []
st = pickle.load(f)
f.close()
s = int(input("Enter the student roll number to delete: "))
for x in st:
if s!=x[0]:
temp.append(x)
f = open("student.dat","wb")
pickle.dump(temp, f)
f.close()
print("\nThe updated file is ")
display()
entry()
delete()
display()

OUTPUT

Enter the limit: 3


Enter the roll number: 1
Enter the name: Shaiban
Enter the roll number: 2
Enter the name: Masroor
Enter the roll number: 3
Enter the name: Nihal

The data in student.dat is:


[1. 'Shaiban']
[2. „Masroor‟]
[3. 'Nihal']

Enter the student roll number to delete: 3


[1. „Shaiban‟]
[2. „Masroor‟]

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy