0% found this document useful (0 votes)
10 views7 pages

XII CS Practicals (1-6)

Uploaded by

allenmano007
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)
10 views7 pages

XII CS Practicals (1-6)

Uploaded by

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

Class XII Computer Science – Practical Questions with Source Code

1. LUCAS SERIES

Date : 27/06/2024 (XII A) 28/06/2024 (XII C)

Aim: To write a python program to generate Lucas Series up to n terms.

Coding:

#Program 1 - Lucas Series

a=int(input("First No? "))

b=int(input("Second No? "))

n=int(input("No. terms to be generated - Lucas Series ? "))

for k in range(n):

c=a+b

print("Lucas #",k+1,"=",c)

a,b=b,c

2. ARMSTRONG NUMBERS.

Date : 27/06/2024 (XII A) 28/06/2024 (XII C)

Aim: To write a python program to generate Armstrong numbers between 100 and 99999.

Coding:

#Program 2 - 3 Digits / 4 Digits / 5 Digits Armstrong Numbers

print("3 / 4 / 5 Digits Armstrong Numbers...")

for x in range(100,100000):

if x>9999:

d=5

elif x>999:

d=4

else:

d=3

k=x

s=0
while(k>0):

s=s+(k%10)**d

k=k//10

if x==s:

print("Armstrong # = ",x)

3. STUDENT REPORT CARD.

Date : 27/06/2024 (XII A) 28/06/2024 (XII C)

Aim: To write a python program to generate report card of a student using STUDENT dictionary.

STUDENT = {STUDNAME : [SUB1, SUB2, SUB3, SUB4, SUB5]}

AVERAGE = TOTAL MARKS / 5

AVERAGE GRADE
More than 90 A1
81-90 A2
71-80 B1
61-70 B2
51-60 C1
41-50 C2
33-40 D
Less than 33 E

Note: If student is failed in any of the subjects (Less than 33), then their Grade will be E.

Coding:

#Program 3 - Student Report Card

def ReportCard(Stud):

for Name in Stud:

Tot=0

Res="Pass"

for k in range(5):

Tot+=Stud[Name][k]

if Stud[Name][k]<33:

Res="Fail"
Avg=Tot/5

if Res=="Pass":

if Avg>90:

Grade="A1"

elif Avg>80:

Grade="A2"

elif Avg>70:

Grade="B1"

elif Avg>60:

Grade="B2"

elif Avg>50:

Grade="C1"

elif Avg>40:

Grade="C2"

else:

Grade="D"

else:

Grade="E"

print("Student Name = ", Stud[Name])

print("Total = ", Tot)

print("Average = ", Avg)

print("Grade = ", Grade)

Student={}

n=int(input("Enter No. of Students? "))

for k in range(n):

SName=input("Enter Student Name? ")

Sub1=int(input("Subject 1 Mark? "))

Sub2=int(input("Subject 2 Mark? "))

Sub3=int(input("Subject 3 Mark? "))


Sub4=int(input("Subject 4 Mark? "))

Sub5=int(input("Subject 5 Mark? "))

Student[SName]=[Sub1,Sub2,Sub3,Sub4,Sub5]

ReportCard(Student)

4. CHECKING VALIDITY OF A PASSWORD.

Date : 27/06/2024 (XII A) 28/06/2024 (XII C)

Aim: To write a python program to check validity of a password during E-Mail registration using the
following criteria:

Password must have minimum of 8 characters. It must have at least one digit, one upper case
alphabet, one special character and spaces are not allowed.

Coding:

#Program 4 - Check validity of a password in E-Mail registration.

name=input("Enter User Name? ")

pwd=input("Enter the Password? ")

c,d,uc,sc,sp=0,0,0,0,0

for k in pwd:

c+=1 #Character count

if k.isdigit():

d+=1 #digit count

elif k.isalpha():

if k.isupper():

uc+=1 #upper case count

elif k.isspace():

sp+=1 #space count

else:

sc+=1 #special character count

if c<8:

print("Invalid password! Minimum 8 characters required...")

elif sp!=0:
print("Invalid password! Spaces are not allowed...")

elif d==0 or uc==0 or sc==0:

print("Invalid password!")

print("Digit/Uppercase/special characters missing...")

else:

print("Password Validation is successful!")

5. FINDING MAXIMUM & MINIMUM VALUE.

Date : 04/07/2024 (XII A) 05/07/2024 (XII C)

Aim: To write a python program to find maximum and minimum Employee name based on both no. of
characters and alphabetical sequence.

Coding:

Country = []

for i in range(n):

cname = input('Enter the country name: ')

Country.append(cname)

Country.sort()

print("Largest Country Name based on ASCII Sequence")

print('Smallest Country Name = ',Country[0])

print('Largest Country Name = ',Country[len(Country)-1])

Country.sort(key=len)

print("Largest Country Name based on No. of Characters")

print('Smallest Country Name = ',Country[0])

print('Largest Country Name = ',Country[len(Country)-1])

m=int(input("Enter No. of Countries? "))

MaxMin(m)

6. COUNTING NUMBER OF CHARACTERS IN A TEXT FILE.

Date : 04/07/2024 (XII A) 05/07/2024 (XII C)

Aim: To write a python program to count No. of lower case , upper case vowels, consonants, digits,
spaces and special characters in a text file “Welcome.txt”
Coding:

file=open ("Welcome.txt","r")

Content=file.read( )

vc, cc, lc, uc = 0, 0, 0, 0

dc, sc, spc = 0, 0, 0

for ch in Content:

if(ch.isalpha()):

if (ch.islower()):

lc += 1

elif (ch.isupper()):

uc +=1

ch=ch.lower()

if (ch in ['a','e','i','o','u']):

vc += 1

else:

cc += 1

elif(ch.isdigit()):

dc += 1

elif(ch.isspace()):

sc += 1

else:

spc += 1

file.close()

print("Number of Vowels :", vc)

print("Number of Consonants :", cc)

print("Number of Lower_case_letters :", lc)

print("Number of Upper_case_letters :", uc)

print("Number of Digits :", dc)


print("Number of Spaces :", sc)

print("Number of Special Characters :", spc)

You might also like