Grab the opportunity to learn all effective java programming language concepts from basic to advance levels by practicing these Java Program Examples with Output
CBSE Class 12 Computer Science Python Programs with Output or python programs class 12 with output are provided in this tutorial. Students who are pursuing 12th can refer to this page for practical files of python programs in order to prepare and learn well for the board exams. Basically, the Class XII python practical file must have 20 python programs and 5 SQL Queries. But today, in this tutorial, we are going to compile some of the important python programs for class 12 CBSE computer science.
Practicing more and more with the provided python practical programs for Class XII CBSE can make you win in the race of python programming and in your software career too. So, dive into this article completely and start learning python programming language easily and efficiently.
List of Python Programs for Class 12 Practical File with Output PDF
Here are some of the python programs for class 12 pursuing students. We have provided 20 Python Programs With Output For Class 12 Pdf.
Just take a look at them before kick starting your programming preparation for board exams, you can get Python Practical Programs For Class 12. Click on the available links and directly jump into the respective python program to understand & continue with other programs that are listed in the CBSE Class 12 Computer Science Python Programming Practical File and Python Practical Programs For Class 12 Pdf
Important python programs for class 12:
- Program for Arithmetic Operations in Python
- Program to Generate a Random Number
- Program to Convert Celsius To Fahrenheit
- Python Program to Check if a Number is Positive, Negative or zero
- Python Program to Check if a Number is Odd or Even
- Python Program to Check Leap Year
- Python Program to Find ASCII Value of given_Character
- Python program to print grades based on marks scored by a student
- Python program to print the sum of all numbers in the given range
- Python program to print all even numbers in given range
- Python program to print star pyramid pattern
- Python program to print number pyramid pattern
- Python program to print Fibonacci numbers to given limit
- Python program to print numbers from 1 to n except 5 multiples
- Python program to split and join a string
- Python program to sort the given list
- Python program to sort a string
- Python Program to Search an element in given list
- Python program to count the frequency of given element in list
- Python program to print list in reverse order
- Python program to Print odd indexed elements in given list
- Python program for Adding two lists in Python(Appending two lists)
- Python program for finding frequency of each element in the given list
- Python program for printing all distinct elements in given list
- Python program to Print even indexed elements in given list
- Python program to Print the given list elements in the same line
- Python program to count distinct characters in the given string
- Python program to Sort the given list elements in descending order
- Python program to print character if ascii value is given
- Python program to split the given number into list of digits
- Python program to split the given string into list of characters
1)Program for Arithmetic Operations in Python
Task is to perform Arithmetic Operations in python
Below is the implementation:
#python program which performs simple arithmetic operations # given two numbers # given first number numberone = 29 numbertwo = 13 # adding the given two numbers addnumb = numberone+numbertwo # printing the result of sum of two numbers print("Adding the given two numbers", numberone, "+", numbertwo, "=", addnumb) # subtracting the given two numbers diffnumb = numberone-numbertwo # printing the result of difference of two numbers print("Subtracting the given two numbers", numberone, "-", numbertwo, "=", diffnumb) # multiply the given two numbers mulnumb = numberone*numbertwo # printing the result of product of two numbers print("Multiplying the given two numbers", numberone, "*", numbertwo, "=", mulnumb) # diving the given two numbers divnumb = numberone+numbertwo # printing the result of sum of two numbers print("Dividing the given two numbers", numberone, "/", numbertwo, "=", divnumb)
Output:
Adding the given two numbers 29 + 13 = 42 Subtracting the given two numbers 29 - 13 = 16 Multiplying the given two numbers 29 * 13 = 377 Dividing the given two numbers 29 / 13 = 42
- Python Program to Create a Countdown Timer
- Python Program to Calculate the Area, Semi Perimeter and Perimeter of a Triangle
- Python Program to Find the Second Largest Number in a List
2)Program to Generate a Random Number
We’ll write a program that produces a random number between a specific range.
Below is the implementation:
# Program which generates the random number between a specific range. # importing random module as below import random # generating random number randNumber = random.randint(1, 450) # print the random number which is generated above print("Generating random numbers between 1 to 450 = ", randNumber)
Output:
Generating random numbers between 1 to 450 = 420
3)Program to Convert Celsius To Fahrenheit
We will convert the given temp in celsius to fahrenheit as below.
Below is the implementation:
# Python program for converting celsius to fahrenheit temperature. # given temp in celsius celsiusTemp = 42.5 # converting the given temp in celsius to fahrenheit temperature fahrenheitTemp = (celsiusTemp * 1.8) + 32 # print the converted temperature value print('Converting the given temp in celsius =', celsiusTemp, " to Fahrenhiet = ", fahrenheitTemp)
Output:
Converting the given temp in celsius = 42.5 to Fahrenhiet = 108.5
4)Python Program to Check if a Number is Positive, Negative or zero
We will write a program to check if the given number is positive number , negative number or zero using if else conditional statements.
Below is the implementation:
# Python Program to Check if a Number is Positive number, Negative number or zero # Function which prints whether the given number #is positive number ,negative number or zero def checkNumber(given_Num): # checking if the given number is positive number if(given_Num > 0): print("The given number", given_Num, "is positive") # checking if the given number is negative number elif(given_Num < 0): print("The given number", given_Num, "is negative") # if the above conditions are not satisfied then the given number is zero else: print("The given number", given_Num, "is zero") # given numbers # given number 1 given_num1 = 169 # passing the given number to checkNumber Function which prints the type of number(+ve,-ve,0) checkNumber(given_num1) # given number 2 given_num1 = -374 # passing the given number to checkNumber Function which prints the type of number(+ve,-ve,0) checkNumber(given_num1) # given number 3 given_num1 = 0 # passing the given number to checkNumber Function which prints the type of number(+ve,-ve,0) checkNumber(given_num1)
Output:
The given number 169 is positive The given number -374 is negative The given number 0 is zero
5)Python Program to Check if a Number is Odd or Even
We will write a program which checks whether the given number is even number or odd number using if else conditional statements.
Below is the implementation:
# Python Program to Check if a Number is Odd or Even # Function which prints whether the given number # is even number ,odd number def checkNumber(given_Num): # checking if the given number is even number if(given_Num % 2 == 0): print("The given number", given_Num, "is even number") # checking if the given number is odd number that is if given number is not even then it is odd number else: print("The given number", given_Num, "is odd number") # given numbers # given number 1 given_num1 = 169 # passing the given number to checkNumber Function which # prints the type of number(even number or odd number) checkNumber(given_num1) # given number 2 given_num1 = 26 # passing the given number to checkNumber Function which # prints the type of number(even number or odd number) checkNumber(given_num1)
Output:
The given number 169 is odd number The given number 26 is even number
6)Python Program to Check Leap Year
We will check whether the given number is leap year or not.
Below is the implementation:
# Python program to check if year is a leap year # given year given_year = 2024 if (given_year % 4) == 0: if (given_year % 100) == 0: if (given_year % 400) == 0: print("Given year", given_year, "is leap year") else: print("Given year", given_year, "is not leap year") else: print("Given year", given_year, "is leap year") else: print("Given year", given_year, "is not leap year")
Output:
Given year 2024 is leap year
7)Python Program to Find ASCII Value of given_Character
We will find the ascii value of given character in python using ord() function.
Below is the implementation:
# Python Program to Find ASCII Value of given_Character # given character given_character = 's' # finding ascii value of given character asciiValue = ord(given_character) # printing ascii value of given character print(" ascii value of given character", given_character, "=", asciiValue)
Output:
ascii value of given character s = 115
8)Python program to print grades based on marks scored by a student
We will display the grades of students based on given marks using if elif else statements.
Below is the implementation:
# Python program to print grades based on marks scored by a student # given marks scored by student given_marks = 68 markGrade = given_marks//10 # cheecking if grade greater than 9 if(markGrade >= 9): print("grade A+") elif(markGrade < 9 and markGrade >= 8): print("grade A") elif(markGrade < 8 and markGrade >= 7): print("grade B+") elif(markGrade < 7 and markGrade >= 6): print("grade B") elif(markGrade < 6 and markGrade >= 5): print("grade C+") else: print("Fail")
Output:
grade B
9)Python program to print the sum of all numbers in the given range
Given two ranges(lower limit range and upper limit range) the task is to print the sum of all numbers in the given range.
i)Using for loop
We will use for loop and range function to literate from lower range limit and upper range limit.
Below is the implementation:
# Python program to print the sum of all numbers in the given range # given lower limit range lower_range = 17 # given upper limit range upper_range = 126 # initializing sum of range to 0 rangeSum = 0 # Using for loop to traverse from lower limit range to upper limit range for i in range(lower_range, upper_range+1): rangeSum = rangeSum+i print("the sum of all numbers between", lower_range, "to", upper_range, "=", rangeSum)
Output:
the sum of all numbers between 17 to 126 = 7865
ii)Using mathematical formula of sum of n natural numbers
We we subtract the sum of upper range limit with lower range limit.
sum of n natural numbers =( n * (n+1) ) /2
Below is the implementation:
# Python program to print the sum of all numbers in the given range # given lower limit range lower_range = 17 # given upper limit range upper_range = 126 low_range = lower_range-1 # calculating the sum of natural numbers from 1 to lower limit range lowSum = (low_range*(low_range+1))/2 # calculating the sum of natural numbers from 1 to upper limit range highSum = (upper_range*(upper_range+1))/2 # calculating the sum of all numbers between the given range rangeSum = highSum-lowSum # printing the sum of all natural numbers between the given range print("the sum of all numbers between", lower_range, "to", upper_range, "=", int(rangeSum))
Output:
the sum of all numbers between 17 to 126 = 7865
10)Python program to print all even numbers in given range
Given two ranges(lower limit range and upper limit range) the task is to print all even numbers in given range
We will use for loop and range function to literate from lower range limit and upper range limit and print all the numbers which are divisible by 2 that is even numbers
Below is the implementation:
# Python program to print the even numbers in # given range(lower limit range and upper limit range) # given lower limit range lower_range = 17 # given upper limit range upper_range = 126 # printing the even numbers in the giveen range using looop # Iterate from lowe limit range to upper limit range for numb in range(lower_range, upper_range+1): # checking if the number is divisible by 2 if(numb % 2 == 0): # we will print the number if the number is divisible by 2 print(numb)
Output:
18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126
11)Python program to print star pyramid pattern
We will print the star pyramid using nested for loops
Below is the implementation:
# Python program to print star pyramid pattern # given number of rows given_rows = 15 for i in range(given_rows+1): for j in range(i): print("*", end=" ") print()
Output:
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
12)Python program to print number pyramid pattern
We will print the number pyramid using nested for loops
Below is the implementation:
# Python program to print star pyramid pattern # given number of rows given_rows = 15 for i in range(1, given_rows+1): for j in range(1, i+1): print(j, end=" ") print()
Output:
1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 1 2 3 4 5 6 1 2 3 4 5 6 7 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 11 1 2 3 4 5 6 7 8 9 10 11 12 1 2 3 4 5 6 7 8 9 10 11 12 13 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
13)Python program to print Fibonacci numbers to given limit
Given two ranges(lower limit range and upper limit range) the task is to print all fibonacci numbers in given range
Below is the implementation:
# Python program to print the all the fibonacci numbers in the given range # given lower limit range lower_range = 2 # given upper limit range upper_range = 1000 first, second = 0, 1 # using while loop while (first < upper_range): if(upper_range >= lower_range and first <= upper_range): print(first) first, second = second, first+second
Output:
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987
14)Python program to print numbers from 1 to n except 5 multiples
We will use the for loop to print all numbers from 1 to n except 5 multiples.
Below is the implementation:
# Python program to print numbers from 1 to n except 5 multiples # given number numb = 49 # using for loop to iterate from 1 to n for num in range(1, numb+1): # if number is not divisible by 5 then print it if(num % 5 != 0): print(num)
Output:
1 2 3 4 6 7 8 9 11 12 13 14 16 17 18 19 21 22 23 24 26 27 28 29 31 32 33 34 36 37 38 39 41 42 43 44 46 47 48 49
15)Python program to split and join a string
Given a string the task is to split the given string and join the string
Example split the string with ‘@’ character and join with ‘-‘ character.
Below is the implementation:
#python program to split and join a string # given string string = "Hello@this@is@BTechGeeks" # splitting thee given string with @ character string = string.split('@') print("After splitting the string the given string =", *string) # joining the given string string = '-'.join(string) print("After joining the string the given string =", string)
Output:
After splitting the string the given string = Hello this is BTechGeeks After joining the string the given string = Hello-this-is-BTechGeeks
16)Python program to sort the given list
We will sort the given list using sort() function
Below is the implementation:
# Python program to sort the given list given_list = ["Hello", "This", "Is", "BTechGeeks"] # printing the list before sorting print("Before sorting the list given list :") print(given_list) # sorting the given list using sort() function given_list.sort() # printing thre list after sorting print("after sorting the list given list :") print(given_list)
Output:
Before sorting the list given list : ['Hello', 'This', 'Is', 'BTechGeeks'] after sorting the list given list : ['BTechGeeks', 'Hello', 'Is', 'This']
17)Python program to sort a string
Given list of strings the task is to sort the strings using sort() function.
We will use the split() function to split the string with spaces and store it in list.
Sort the list.
Below is the implementation:
# Python program to sort a string given_string = "Hello This Is BTechGeeks" # split the given string using spilt() function(string is separated by spaces) given_string = given_string.split() # printing the string before sorting print("Before sorting the sorting given sorting :") print(*given_string) # sorting the given string(list) using sort() function given_string.sort() # printing the string after sorting print("after sorting the string given string :") print(*given_string)
Output:
Before sorting the sorting given sorting : Hello This Is BTechGeeks after sorting the string given string : BTechGeeks Hello Is This
18)Python Program to Search an element in given list
Given a list and the task is to search for a given element in the list .
We will use the count function to search an element in given list.
If the count is 0 then the element is not present in list
Else the given element is present in list
Below is the implementation:
# Python program to search an element in given list given_list = ["Hello", "This", "Is", "BTechGeeks"] # given element to search element = "BTechGeeks" # using count function to check whether the given element the present in list or not countelement = given_list.count(element) # if count of element is zero then element is not present in list if(countelement == 0): print("The given element", element, "is not present in given list") else: print("The given element", element, "is present in given list")
Output:
The given element BTechGeeks is present in given list
19)Python program to count the frequency of given element in list
Given a list and the task is to find the frequency of a given element in the list .
We will use the count function to find frequency of given element in given list.
Below is the implementation:
# Python program to count the frequency of given element in list given_list = ["Hello", "BTechGeeks", "This", "Is", "BTechGeeks"] # given element to search element = "BTechGeeks" # using count function to count the given element in list countelement = given_list.count(element) # printing the count print("The given element", element, "occurs", countelement, "times in the given list")
Output:
The given element BTechGeeks occurs 2 times in the given list
20)Python program to print list in reverse order
We will use slicing to print the given list in reverse order
Below is the implementation:
# Python program to print list in reverse order given_list = ["Hello", "This", "Is", "BTechGeeks"] # printing the list before reversing print("printing the list before reversing :") print(given_list) # reversing the given list given_list = given_list[::-1] # printing the list after reversing print("printing the list after reversing :") print(given_list)
Output:
printing the list before reversing : ['Hello', 'This', 'Is', 'BTechGeeks'] printing the list after reversing : ['BTechGeeks', 'Is', 'This', 'Hello']
21)Python program to Print odd indexed elements in given list
We will use slicing to print the odd indexed elements in the given list .
Below is the implementation:
# Python program to Print odd indexed elements in given list given_list = ["Hello", "This", "Is", "BTechGeeks", "Online", "Platform"] # odd indexed elements in given list using slicing odd_elements = given_list[1::2] # printing the odd indexed elements in given list for i in odd_elements: print(i)
Output:
This BTechGeeks Platform
22)Python program for Adding two lists in Python(Appending two lists)
We will use the + operator to add(append) the two lists in python as below:
Below is the implementation:
# Python program for Adding two lists in Python(Appending two lists) # given list 1 given_list1 = ["Hello", "This", "Is", "BTechGeeks", "Online", "Platform"] # given list 2 given_list2 = ["Good", "Morning", "Python"] # adding two lists using + operator # we add all the elements of second list to first list given_list1 = given_list1+given_list2 # print the result after adding the two lists for i in given_list1: print(i)
Output:
Hello This Is BTechGeeks Online Platform Good Morning Python
23)Python program for finding frequency of each element in the given list
We will use the counter function to calculate the frequency of each element in the given list in efficient way.
Below is the implementation:
# Python program for finding frequency of each element in the given list # importing counter function from collections from collections import Counter # given list which may contains the duplicates given_list1 = ["Hello", "this", "is", "this", "is", "BTechGeeks", "Hello", "is", "is", "this", "BTechGeeks", "is", "this", "Hello", "python"] # finding frequency of each elements using Counter() function freqcyCounter = Counter(given_list1) # printing the frequency of each element for key in freqcyCounter: # frequency of the respective key count = freqcyCounter[key] # print the element and its frequency print("The element", key, "Has frequency =", count)
Output:
The element Hello Has frequency = 3 The element this Has frequency = 4 The element is Has frequency = 5 The element BTechGeeks Has frequency = 2 The element python Has frequency = 1
24)Python program for printing all distinct elements in given list
We will use counter function and print all the keys in it
Below is the implementation:
# Python program for printing all distinct elements in given list # importing counter function from collections from collections import Counter # given list which may contains the duplicates given_list1 = ["Hello", "this", "is", "this", "is", "BTechGeeks", "Hello", "is", "is", "this", "BTechGeeks", "is", "this", "Hello", "python"] # finding frequency of each elements using Counter() function freqcyCounter = Counter(given_list1) # printing the distinct elements of the given list print("printing the distinct elements of the given list :") for key in freqcyCounter: print(key)
Output:
printing the distinct elements of the given list : Hello this is BTechGeeks python
25)Python program to Print even indexed elements in given list
We will use slicing to print the even indexed elements in the given list .
Below is the implementation:
# Python program to Print even indexed elements in given list given_list = ["Hello", "This", "Is", "BTechGeeks", "Online", "Platform"] # odd indexed elements in given list using slicing odd_elements = given_list[::2] # printing the even indexed elements in given list print("printing the even indexed elements in given list :") for i in odd_elements: print(i)
Output:
printing the even indexed elements in given list : Hello Is Online
26)Python program to Print the given list elements in the same line
We have two methods to print the given lists elements in the same line
i)Using end
Below is the implementation:
# Python program to Print the given list elements in the same line given_list = ["Hello", "This", "Is", "BTechGeeks", "Online", "Platform"] # Traveersing the list using for loop # printing the given list elements print("printing the given list elements :") for element in given_list: print(element, end=" ")
Output:
printing the given list elements : Hello This Is BTechGeeks Online Platform
ii)Using * operator
We can use * operator to print all the elements of given list in single line
Below is the implementation:
# Python program to Print the given list elements in the same line given_list = ["Hello", "This", "Is", "BTechGeeks", "Online", "Platform"] # printing the given list elements print("printing the given list elements :") print(*given_list)
Output:
printing the given list elements : Hello This Is BTechGeeks Online Platform
27)Python program to count distinct characters in the given string
We will use counter function and print all the keys in it to print all distinct characters in given string
Below is the implementation:
# Python program to count distinct characters in the given string # importing counter function from collections from collections import Counter # given string string = "Hello@--472BtechGeeks!!;<>?" # using counter function distchars = Counter(string) # Traversing through distchars dictionary # printing the distinct characters in given string print("printing the distinct characters in given string", string) for key in distchars: print(key)
Output:
printing the distinct characters in given string Hello@--472BtechGeeks!!;<>? H e l o @ - 4 7 2 B t c h G k s ! ; < > ?
28)Python program to Sort the given list elements in descending order
We will use the sort() and reverse=True to sort the given list in descending order
Below is the implementation:
# Python program to sort the given list in descending order given_list = ["Hello", "This", "Is", "BTechGeeks", "online", "platform"] # printing the list before sorting print("Before sorting the list given list :") for i in given_list: print(i) # sorting the given list using sort() function given_list.sort(reverse=True) # printing the list after sorting print("after sorting the list given list in descending order:") for i in given_list: print(i)
Output:
Before sorting the list given list : Hello This Is BTechGeeks online platform after sorting the list given list in descending order: platform online This Is Hello BTechGeeks
29)Python program to print character if ascii value is given
We will use chr function to print character if ascii value is given
Below is the implementation:
# Python program to print character if ascii value is given # given ascii value givenvalue = 104 # getting the character having given ascii value character = chr(givenvalue) # printing the character having given ascii value print("The character which is having ascii value", givenvalue, "=", character)
Output:
The character which is having ascii value 104 = h
30)Python program to split the given number into list of digits
We will use map and list function to split the given number into list of digits
Below is the implementation:
# Python program to split the given number into list of digits # given number numb = 123883291231775637829 # converting the given number to string strnu = str(numb) # splitting the given number into list of digits using map and list functions listDigits = list(map(int, strnu)) # print the list of digits of given number print(listDigits)
Output:
[1, 2, 3, 8, 8, 3, 2, 9, 1, 2, 3, 1, 7, 7, 5, 6, 3, 7, 8, 2, 9]
31)Python program to split the given string into list of characters
We will use the list() function to split the given string into list of characters
Below is the implementation:
# Python program to split the given string into list of characters # given string string = "HellothisisBtechGeeks" # splitting the string into list of characters splitstring = list(string) # print the list of characters of the given string print(splitstring)
Output:
['H', 'e', 'l', 'l', 'o', 't', 'h', 'i', 's', 'i', 's', 'B', 't', 'e', 'c', 'h', 'G', 'e', 'e', 'k', 's']
Here the string is converted into a list of characters.
Objectives to Practice Python Programming for Class XII Computer Science CBSE Exam
- Students should have the understanding power to implement functions and recursion concepts while programming.
- They study the topics of file handling and utilize them respectively to read and write files as well as other options.
- Learn how to practice efficient concepts in algorithms and computing.
- Also, they will be proficient to create Python libraries and utilizing them in different programs or projects.
- Can learn SQL and Python together with their connectivity.
- Students can also understand the basics of computer networks.
- Furthermore, they will have the ability to practice fundamental data structures such as Stacks and Queues.
Must Check: CBSE Class 12 Computer Science Python Syllabus
Further reference and doubts we have given information in the form of Python Programming Questions For Class 12 given below.
FAQs on Python Practical Programming for 12th Class CBSE
1. From where students can get the list of python programs for class 12?
Students of class 12 CBSE can get the list of python practical programs with output from our website @ Btechgeeks.com
2. How to download a class 12 CBSE Computer Science practical file on python programming?
You can download CBSE 12th Class Computer science practical file on python programming for free from the above content provided in this tutorial.
3. What is the syllabus for class 12 python programming?
There are 3 chapters covered in the computer science syllabus of class 12 python programs to learn and become pro in it. You can get the information on Python Programs For Class 12 Practical File With Output Pdf. The chapters covered in cse syllabus are:
- Computational Thinking and Programming – 2
- Computer Networks
- Database Management