















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
PRACTICAL PROGRAMS GRADE 12 CBSE
Typology: Study Guides, Projects, Research
1 / 23
This page cannot be seen from the preview
Don't miss anything!
















ODD AND EVEN CALCULATOR
import random def counter(): count=[] for k in range(100): count.append(random.randint(1,100)) odd= even= for num in count: if num in count: if num%2==0: even+= odd=100-even print("odd numbers:",odd,"even numbers:",even) counter()
Grade and Grade-Point Calculator
def grades(g): if g in range(91,100): print("grade:a1,grade point:10.0") elif g in range(81,90): print("grade:a2,grade point:9.0") elif g in range(71,80): print("grade:b1,grade point:8.0") elif g in range(61,70): print("grade:b2,grade point:7.0") elif g in range(51,60): print("grade:c1,grade point:6.0") elif g in range(41,50): print("grade:c2,grade point:5.0") elif g in range(33,40): print("grade:d,grade point:4.0") elif g in range(21,32): print("grade:e1,grade point:0.0") elif g in range(00,20): print("grade:e2,grade point:0.0") name=input("enter the name of student:") chem=int(input("enter the marks in chem:")) grades(chem) maths=int(input("enter the marks in maths:")) grades(maths) phy=int(input("enter the marks in phy:"))
Series Generator
def factorial(n): fact= for i in range(1,n+1): fact=k return fact def power (x,n): return x(2n) n=int(input("enter the number(n):")) x=int(input("enter the number(x):")) series= for k in range(1,n+1): series+=power(x,k)/factorial(k) print("sum is equal to:",series)
Number checker Create following functions: a) def perfect(n) – to check whether a number is perfect or not, it returns True or False. b) def palindrome(n)- to check whether a number is palindrome or not. c) def armstrong(n) – to check whether a number is armstrong no or not. d) def is_Prime( n)- to check whether a number is prime or not and returns True, if the argument is prime number, or False otherwise. e) def automorphic(n) -to check whether a number is an automorphic number. A number is said to be an automorphic number if it contains last digit(s) of its square. E.g., 25 is automorphic number as its square is 625 and 25 is present in its last two digits. Write a menu driven program to call above functions based upon user’s choice.
while true: ch=int(input("enter your choice")) print() if ch==1: n=int(input("enter the number:")) print(perfect(n)) print() if ch==2: n=int(input("enter the number")) palindrome(n) print() if ch==3: n=int(input("enter the number")) armstrong(n) print() if ch==4: n=int(input("enter the number") print(is_prime(n)) print() if ch==5: n=int(input("enter number")) print(automorphic(n)) print() if ch==6: print("exit program..") break
COUNTER
def vowelcount(): count= for i in st: if i in"aeiouAEIOU": count=count+ print("the no of vowels are",count) def consocount(): count= for i in st: if i.isalpha(): if i not in "aeiouAEIOU": count=count+ print("the number of consonants",count) def uppercountt(): count= for i in st:
elif ch==5: break else: print("invalid choice")
PALINDROME CHECKER
def palindrome(s): rev="" for i in range(len(s)-1,-1,-1): rev+=s[i] return rev==s s=input("enter the string") print(palindrome(s))
for i in st: copy+=i return copy def sconcat(st1,st2): st3="" for i in st1: st3+=i for j in st2: st3+=j return st print("-----MENU----") print("1-convert the string to uppercase") print("2-convert the string into lowercase") print("3-calculate the length of string") print("4-copy the string") print("concatenate two strings") print("exit") while True: ch=int(input("enter the choice")) if ch==1: st=input("enter the string") print("uppercase",uppit(st)) if ch==2: st=input("enter the string") print("lowercase",loit(st)) if ch==3: st=input("enter the string") print("length",length(st)) if ch==4: st=input("enter the string") print("copy",scopy(st)) if ch==5: st1=input("enter string1") st2=input("enter string2") print("new string",sconcat(st1,st2)) if ch==6:
print("exit") break