Practical File
Practical File
Practical File
Class - XII-PCM(B)
Roll No. - 33
Sr. No. – 4096
Subject – Coumputer
Science
line=input(“enter a line:”)
lowercount=uppercount=0
digitcount=alphacount=0
for a in line:
if a.islower():
lowercount+=1
elif a.isupper():
uppercount+=1
elif a.isdigit():
digitcount+=1
if a.isalpha():
alphacount+=1
print(“Number of uppercase
letters:”,uppercount)
print(“Number of lowercase letters:”,
lowercount)
print(“Number of alphabets:”,
alphacount)
print(“Number of digit:”, digitcount)
3. Program to create a dictionary containing
name of student and number of wins...
filepath = 'story.txt'
vowels="AEIOUaeiou"
with open(filepath) as fp:
line = fp.readline()
cnt = 1
while line:
if(line[0] in vowels):
#print(line)
print("Line {}: {}".
format(cnt, line.strip()))
cnt=cnt+1
line = fp.readline()
5. Program to take input for 3 numbers,
check and print the largest number?
def count_alpha():
lo=0
with open("story.txt") as f:
while True:
c=f.read(1)
if not c:
break
print(c,end='')
if((c>='A' and c<='Z') or
(c>='a' and c<='z')):
lo=lo+1
print("total lower case
alphabets ",lo)
#function calling
count_alpha()
8. Program to read a file named “story.txt”,
count and print total lines starting with
vowels in the file?
filepath = 'story.txt'
vowels="AEIOUaeiou"
with open(filepath) as fp:
line = fp.readline()
cnt = 1
while line:
if(line[0] in vowels):
#print(line)
print("Line {}:
{}".format(cnt, line.strip()))
cnt=cnt+1
line = fp.readline()
9. Program for calculating simple interest.
classxii=dict()
n=int(input("Enter total number of
section in xi class: "))
i=1
while i<=n:
a=input("Enter Section: ")
b=input("Enter stream name:")
classxi [a]=b
i=i+1
print ("class","\t","section", '\
t',"Stream name")
for i in classxii:
print ("XI", '\t',i,'\
t', classxi [i])
11. Program to accept username "Admin"
as default argument and password 123
entered by user to allow login into the
system.
def user_pass(password,username="
Admin"):
if password=='123':
print("You have logged into system")
else:
print("Password is incorrect!!!!!!")
password=input("Enter the password:")
user_pass(password)
12. Create a binary file client.dat to hold
records like ClientID, Client name, and
Address using the dictionary. Write
functions to write data, read them, and print
on the screen.
import pickle
rec={}
def file_create():
f=open("client.dat","wb")
cno = int(input("Enter Client ID:"))
cname = input("Enter Client Name:")
address = input("Enter Address:")
rec={cno:[cname,address]}
pickle.dump(rec,f)
def read_data():
f = open("client.dat","rb")
print("*"*78)
print("Data stored in File....")
rec=pickle.load(f)
for i in rec:
print(rec[i])
file_create()
read_data()
13. Check whether a given number is a
palindrome.
n=int(input("Enter any Number: "))
rev=0
ori=n
while(n>0):
d=n%10
rev=(rev*10)+d
n=n//10
print("Reverse of a given number is =
%d" %rev)
if(ori == rev):
print("%d is a Palindrome Number"
%ori)
else:
print("%d is not a Palindrome
Number" %ori)
14. Program to write student record into
binary file ‘student.dat’.
import pickle
lst =[]
while True:
roll = input("Enter roll number:")
name = input("Enter name of
student:")
student = {"roll" :roll,
"sname" :name}
lst.append(student)
choice = input("Want to add more
record(y/n):")
if (choice=='n'):
break
file = open("student.dat",'wb')
pickle.dump(lst,file)
file.close()
15. Program to Exchange the Values of Two
Numbers
def swap(x, y):
temp = x
x = y
y = temp
print("After swapping")
print("Value of first number :", x)
print("Value of second number :",
y)
num1=int(input("Enter first number :"))
num2=int(input("Enter second
number :"))
print("Before swapping")
print("Value of first number :",num1)
print("Value of second number :",num2)
swap(num1,num2)