25+ best Programs for Computer practical file Class 12

In this article, you will get 10 best Programs for Computer practical file Class 12. These programs can be useful for your practical file for the board examination.

Here we provide the code of assignment questions shared earlier. 

10 best Programs for Computer practical file Class 12

Let’s start the article Computer practical file Class 12 with basic function programs.

1. Write a python program to perform the basic arithmetic operations in a menu-driven program with different functions. The output should be like this: 

Select an operator to perform the task:

  •  ‘+’ for Addition 
  •  ‘-‘ for Subtraction 
  •  ‘*’ for Multiplication 
  •   ‘/’ for Division
def main():
    print('+ for Addition')
    print('- for Subtraction')
    print('* for Multiplication')
    print('/ for Division')
    ch = input("Enter your choice:")
    if ch=='+':
        x=int(input("Enter value of a:"))
        y=int(input("Enter value of b:"))  
        print("Addition:",add(x,y))
    elif ch=='-':
        x=int(input("Enter value of a:"))
        y=int(input("Enter value of b:"))  
        print("Subtraction:",sub(x,y))
    elif ch=='*':
        x=int(input("Enter value of a:"))
        y=int(input("Enter value of b:"))  
        print("Multiplication",mul(x,y))
    elif ch=='/':
        x=int(input("Enter value of a:"))
        y=int(input("Enter value of b:"))  
        print("Division",div(x,y))
    else:
        print("Invalid character")  
def add(a,b):
    return a+b
def sub(a,b):
    return a-b
def mul(a,b):
    return a*b
def div(a,b):
    return a/b
main()

2. Write a python program to enter a temperature in Celsius into Fahrenheit by using a function.

def tempConvert():
  cels = float(input("Enter temperature in celsius: "))
  fh = (cels * 9/5) + 32
  print('%.2f Celsius is: %0.2f Fahrenheit' %(cels, fh))
  tempConvert()

3. Write a python program using a function to print Fibonacci series up to n numbers.

def fibo():
    n=int(input("Enter the number:"))
    a=0
    b=1
    temp=0
    for i in range(0,n):
        temp = a + b
        b = a 
        a= temp
        print(a, end=" ")
fibo()

4. Write a python program to return factorial series up to n numbers using a function.

def facto():
    n=int(input("Enter the number:"))
    f=1
    for i in range(1,n+1):
        f*=i
        print(f, end=" ")
facto()

Now the next programs for the Computer practical file Class 12  are based on parameters passing.

5. Write a python program to accept the username “Admin” as the default argument and password 123 entered by the 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)

6. Write a menu-driven python program using different functions for the following menu:

  1. Check no. is Palindrome or not
  2. Check no. is Armstrong or not
  3. Exit
def checkPalin(n):
    temp=n
    rem=0
    rev=0
    while(n>0):
        rem=n%10
        rev=rev*10+rem
        n=n//10
    if(temp==rev):
        print("The number is a palindrome!")
    else:
        print("The number is not a palindrome!")
def checkArmstrong(n):
temp=n
    rem=0
    arm=0
    while(n>0):
        rem=n%10
        arm+=rem**3
        n=n//10
    if(temp==arm):
        print("The number is an armstrong!")
    else:
        print("The number is not an armstrong!")
def menu():
    print("1.Check no. is Palindrome:")
    print("2.Check no. is Armstrong:")
    print("3.Exit")
    opt=int(input("Enter option:"))
    no=int(input("Enter number to check:"))
    if opt==1:
            checkPalin(no)
    elif opt==2:
        checkArmstrong(no)
    elif opt==3:
        sys.exit()
    else:
        print("Invalid option")
menu()

7. Write a python program using a function to print prime numbers between n to m.

def prime(st,en):
   print("Prime numbers between", start, "and", end, "are:")
   for n in range(st, en + 1):
   if n > 1:
       for i in range(2, n):
           if (n % i) == 0:
               break
       else:
           print(n,",",end=" ")


start =11
end =200
prime(st,en)

The next program for the Computer practical file Class 12  is based on variable-length argument.

8. Write a python program to demonstrate the concept of variable length argument to calculate the sum and product of the first 10 numbers.

def sum10(*n):
    total=0
    for i in n:
        total=total + i
    print("Sum of first 10 Numbers:",total)
sum10(1,2,3,4,5,6,7,8,9,10)

def product10(*n):
    pr=1
    for i in n:
       pr=pr * i
    print("Product of first  10 Numbers:",pr)
product10(1,2,3,4,5,6,7,8,9,10)

The next program for the Computer practical file Class 12 is based on a different logic.

9. Write a python program to find maximum and minimum numbers among the given 4 numbers.
Method 1: Using If..elif..else

def find_max():
    n1=int(input("Enter number1:"))
    n2=int(input("Enter number2:"))
    n3=int(input("Enter number3:"))
    n4=int(input("Enter number4:"))
    if n1>n2 and n1>n3 and n1>n4:
        print(n1," is maximum")
    elif n2>n1 and n2>n3 and n2>n4:
        print(n2," is maximum")
    elif n3>n1 and n3>n2 and n3>n4:
        print(n3," is maximum")
    elif n4>n1 and n4>n2 and n4>n3:
        print(n2," is maximum")
    else:
        print("All are equals")

Method 2: Using list

def find_max():
    l=[]
    max1=0
    for i in range(4):
        n=int(input("Enter number into list:"))
        l.append(n)
    print("The list is:",l)
    for i in l:
        if i>max1:
            max1=i
    print("Max:",max1)

Method 3: Using max function

def find_max():
    l=[]
    max1=0
    for i in range(4):
        n=int(input("Enter number into list:"))
        l.append(n)
    max1=max(l)
    print("Max:",max1)

Method 4: Using sort() function

def find_max():
    l=[]
    max1=0
    for i in range(4):
        n=int(input("Enter number into list:"))
        l.append(n)
    l.sort()
    print("Max:",l[-1])

The last program for the Computer practical file Class 12 is based on diagram patterns.

10. Write a python program to print the following patterns using functions:

  1. Diamond Pattern with *
  2. Butterfly Pattern with *
  3. Triangle Pattern with *
def pattern_diamond(n): 
    no = 0
    for i in range(1, n + 1):
        for j in range (1, (n - i) + 1):
            print(end = " ")  
        while no != (2 * i - 1):
            print("*", end = "") 
            no = no + 1
        no = 0
        print()  
    k = 1
    no = 1
    for i in range(1, n): 
        for j in range (1, k + 1): 
            print(end = " ") 
        k = k + 1
        while no <= (2 * (n - i) - 1): 
            print("*", end = "") 
            no = no + 1
        no = 1
        print() 
num=int(input("Enter no or lines to print:"))
pattern_diamond(num)
    
def pattern_butterfly(n): 
    for i in range(1, n + 1): 
        for j in range(1, 2 * n + 1): 
            if (i < j): 
                print("", end = " "); 
            else: 
                print("*", end = ""); 
            if (i <= ((2 * n) - j)): 
                print("", end = " "); 
            else: 
                print("*", end = ""); 
        print(""); 
    for i in range(1, n + 1): 
        for j in range(1, 2 * n + 1): 
            if (i > (n - j + 1)): 
                print("", end = " "); 
            else: 
                print("*", end = ""); 
            if ((i + n) > j): 
                print("", end = " "); 
            else: 
                print("*", end = ""); 
        print(""); 
num=int(input("Enter no or lines to print:"))
pattern_butterfly(num);

def pattern_triangle(n): 
    for i in range(1, n+1): 
        for j in range(1, i+1): 
            print("* ",end="") 
        print("r") 
num=int(input("Enter no or lines to print:"))
pattern_triangle(num)

Follow this link to download the file:

Computer Science Class 12 Textbook programs Sumita Arora – Type C Programming Practice/Knowledge-based questions

  1. Write a function that takes amount-in-dollars and dollar-to-rupee conversion price; it then returns the amount converted to rupees. Create the function in both void and non-void forms.
def void_dollar_to_rupee(dollar):
  r=dollar*76.22
  print("Void function:$", dollar, "=",r,"Rs")

def non_void_dollar_to_rupee(dollar):
  return dollar*76.22

d=float(input("Enter amount to convert:"))
void_dollar_to_rupee(d)
print("Calling non-void function:",d,"=",non_void_dollar_to_rupee(d),"Rs")

2. Write a function to calculate volume of a box with appropriate default value for its parameters. Your function should have the following input parameters:

(a) length of box

(b) width of box

(c) height of box

Test it by writing a complete program to invoke it.

def volume_of_box(l,b,h):
  return l*b*h

length=int(input("Enter the length of box:"))
width=int(input("Enter the width of box:"))
height=int(input("Enter the height of box:"))
volume=volume_of_box(length,width,height)
print("The volume of box is:",volume)

3. Write a program to have the following functions:

i) A function that takes a number as an argument and calculates a cube for it. The function does not return a value. If there is no value passed to the function in a function call, the function should calculate a cube of 2.

ii) Write a function that takes two char arguments and returns True if both arguments equal otherwise False.

Test both these functions by giving appropriate function call statements.

def cube(n=2):
  c=n**3
  print("The cube of ",n," is:",c)


def str_equals(txt1,txt2):
  if txt1==txt2:
    return True
  else:
    return False

#Take number to compute cube
no=int(input("Enter the number:"))

#calling cube() function without argument
print("Function without argument or default argument:")
cube()

#calling cube() function with argument
cube(no)

text1=input("Enter text 1:")
text2=input("Enter text 2:")
e=str_equals(text1,text2)
print("The text is qual:"e)

4. Write a function that receives two numbers and generates a random number from that range. Using function the main should be able to print three numbers randomly.

import random
def random_num(x,y):
  return random.randint(x,y)
n1=int(input("Enter the first number:"))
n2=int(input("Enter the second number:"))
print("Random No.1:",random_num(n1,n2))
print("Random No.2:",random_num(n1,n2))
print("Random No.3:",random_num(n1,n2))

5. Write a function that receives two string arguments and checks whether they are same-length strings. (returns True in this case otherwise False).

def samelength(txt1,txt2):
  if len(txt1)==len(txt2):
    return True
  else:
    return False

text1=input("Enter the text1:")
text2=input("Enter the text2:")
print("The string is same length?",samelength(text1,text2))

6. Write a function namely nthRoot() that receives two parameters x and n and returns nth root of x. The default value is 2.

def nthRoot(x,n=2):
  return x**(1/n)

n=int(input("Enter number for nth root:"))
x=int(input("Enter value:"))
print("The ",n,"th root of ",x," is:",nthRoot(x,n))

7. Write a function that takes a number n and then returns a randomly generated number having exactly n digits (not starting with zero). e.g. if n is 2 then function and randomly return a number 10-99 but 07,02 etc. are not valid number two-digit numbers.

So I hope these programs will help you to prepare your Computer practical file Class 12. If you have any doubt about the same feel free to ask in the comment section

Don’t forget to share your views, comments and feedback in the comment section for the Computer practical file Class 12 .

One thought on “25+ best Programs for Computer practical file Class 12”

Leave a Reply