XII CS Practicals (1-6)
XII CS Practicals (1-6)
1. LUCAS SERIES
Coding:
for k in range(n):
c=a+b
print("Lucas #",k+1,"=",c)
a,b=b,c
2. ARMSTRONG NUMBERS.
Aim: To write a python program to generate Armstrong numbers between 100 and 99999.
Coding:
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)
Aim: To write a python program to generate report card of a student using STUDENT dictionary.
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:
def ReportCard(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"
Student={}
for k in range(n):
Student[SName]=[Sub1,Sub2,Sub3,Sub4,Sub5]
ReportCard(Student)
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:
c,d,uc,sc,sp=0,0,0,0,0
for k in pwd:
if k.isdigit():
elif k.isalpha():
if k.isupper():
elif k.isspace():
else:
if c<8:
elif sp!=0:
print("Invalid password! Spaces are not allowed...")
print("Invalid password!")
else:
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):
Country.append(cname)
Country.sort()
Country.sort(key=len)
MaxMin(m)
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( )
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()