In this article, you will get 10 best Programs for Computer practical file Class 12. This 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 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 Computer practical file Class 12Â are based on parameters passing.
5. Write a python 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)
6. Write menu-driven python program using different functions for the following menu:
- Check no. is Palindrome or not
- Check no. is Armstrong or not
- 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 11 to 200.
start =11
end =200
print("Prime numbers between", start, "and", end, "are:")
for n in range(start, end + 1):
if n > 1:
for i in range(2, n):
if (n % i) == 0:
break
else:
print(n,",",end=" ")
The next program for 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 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 Computer practical file Class 12Â id based on different logics.
9. Write a python program to find maximum and minimum numbers among 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 Computer practical file Class 12Â is based on diagram patterns.
10. Write a python program to print the following patterns using functions:
- Diamond Pattern with *
- Butterfly Pattern with *
- 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 file:
So I hope these programs will help you to prepare your Computer practical file Class 12Â . If you have any doubt for 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 Computer practical file Class 12Â .