0% found this document useful (0 votes)
31 views16 pages

KV2 TBM Practical Record 24-25

The document contains a series of practical Python programming exercises designed for students at PM SHRI KENDRIYA VIDYALAYA No.2, AFS, TAMBARAM, in preparation for the CBSE Board Examination 2024-2025. Each practical includes objectives, source code, output examples, and a confirmation of successful execution. Topics covered include number swapping, addition, factorial calculation, palindrome checking, and more.

Uploaded by

ramkrishaanth09
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views16 pages

KV2 TBM Practical Record 24-25

The document contains a series of practical Python programming exercises designed for students at PM SHRI KENDRIYA VIDYALAYA No.2, AFS, TAMBARAM, in preparation for the CBSE Board Examination 2024-2025. Each practical includes objectives, source code, output examples, and a confirmation of successful execution. Topics covered include number swapping, addition, factorial calculation, palindrome checking, and more.

Uploaded by

ramkrishaanth09
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

PM SHRI KENDRIYA VIDYALAYA No.

2, AFS, TAMBARAM

BONAFIDE CERTIFICATE

This is certified to be the bonafide work of the student in

Artificial Intelligence (Subject code: 417) for the CBSE

Board Examination 2024-2025.

Class & Section :

Name of the student :

Roll No :

EXAMINER PRINCIPAL
Practical No. 1

Objective:

Write a Python program to swap two numbers.

Source Code:

num1 = float(input(“Enter the first number: “)) //prompt user for entering number

num2= float(input(“Enter the second number: “))

#Display the original number first

print(“Original Values: num1 = {num1}, num2 = {num2}”)

#Swap two numbers using the temp variable

temp = num1

num1 = num2

num2 = temp

#Display the swapped numbers

print(f “Value after Swapping values: num1 = {num1}, num2 = {num2}”)

Output:

Enter the first number: 14

Enter the second number: 51

Original values: num1 = 14, num2 = 51

Value after Swapping: num1 = 51, num2 = 14

Result:

Thus, the program was executed successfully.


Practical No. 2

Objective:

Write a program to add two numbers using Python.

Source Code:

#Basic code for Python to add two numbers

num1 = float(input(“Enter the first number: “)) //prompt user for entering number

num2= float(input(“Enter the second number: “))

#Create a variable to store the sum of the two numbers.

sum = num1 + num2

print(“The sum of {num1} and {num2} is {sum}”)

Output

Enter the first number: 15

Enter the second number: 7

The sum of 15 and 7 is 22

Result:

Thus, the program was executed successfully.


Practical No. 3

Objective:

Write a basic Python program for finding the factorial of a number.

Source Code:

#Function for finding the factorial of a number using Python

def factorial (n):

if (n == 1 or n == 0): //If numbers are 0 and 1, then return 1.

return 1

else:

return n * factorial (n-1) //Factorial using recursion

int num = int(input(“Enter a number to calculate factorial of number: ”)

print(“Factorial of”, num, “is”, factorial(num))

Output

Enter the number to calculate the factorial:

Factorial of 6 is 720

Result:

Thus, the program was executed successfully.


Practical No. 4

Objective:

Write a program to determine the sum of the first n natural numbers using Python
program

Source Code:

#Function to calculate the sum of n numbers using Python.

It can be calculated using simple repeated addition.

num = int (input(“Enter the number: ”))

if num<0:

print(“Negative numbers are not allowed.”)

else:

sum = 0

i = num

while(i>0):

sum+=i

i = i-1

print( “ Sum of first {num} natural number is”, num)

Output

Enter the number: 6

Sum of first 6 natural number is 21


Practical No. 5

Objective:

Write a Python program to check whether a string is a palindrome.

Source Code:

#Python function to check whether a string is a palindrome.

def isPalindrome(str)

#Remove spaces and convert them into lowercase letters.

final_string = ‘ ’.join(str.split()).lower()

return rev = final_string[: : -1]

int str_input = input(“Enter a string: ” )

if (is_palindrome(str_input):

print(f “{str_input} is a palindrome.”)

else:

print(f”{str_input} is not a palindrome.”)

Output

Enter a string:

madam

Radar is a palindrome.

Result:

Thus, the program was executed successfully.


Practical No. 6

Objective:

Write a Python program to reverse a string.

Source Code:

#Python function to check whether a string is a palindrome.

str = input(“Enter a string: ”)

reverse_str = str[ : : -1]

print(f “The reversed string is {reverse_str}.”)

Output

Enter a string:

Kendriya Vidyalaya

The reversed string is ayalaydiVayirdneK.

Result:

Thus, the program was executed successfully.


Practical No. 7

Objective:

Write a Python program to check whether a year is a Leap Year.

Source Code:

#Function to predict whether a given year is a Leap year.

def is_Leap_Year (year):

#If the given year is divisible by 4 and not divisible by 100, then it is a leap year. Also, if the given
year is divisible by 400, then it is a leap year.

if (year%4 == 0 and year%100!=0) or (year%400 ==0):

return True

else:

return False

year_inp = int(input(“Enter a year:”)) //Take input from the user.

if is_Leap_Year(year_inp):

print(f “{year_inp} is a leap year.”)

else:

print(f”{year_inp} is not a leap year.”)

Output

Year =2000

2000 is a leap year

Year 2001

2001 is not a leap year

Result:

Thus, the program was executed successfully.


Practical No. 8

Objective:

Write a Python Program to check whether the given character is a vowel or


consonant.

Source Code:

#Ask the user for input of a character (vowel or consonant)

ch = input(“Enter a character: “)

if(ch == ‘a’ or ch == ‘e’ or ch == ‘i’ or ch == ‘o’ or ch == ‘u’):

print(“The given character”, ch, “is a vowel.”) //if the character is found to be vowel

else:

Print (“Given character”, ch, “is a consonant.”) //if the given character is consonant.

Output

Enter a character:

The given character e is a vowel.

Result:

Thus, the program was executed successfully.


Practical No. 9

Objective:

Write a Python program to remove spaces from a string without using inbuilt
functions.

Source Code:

#First take input from the user

str = input(“Enter a string: ”)

result = “ ”

#iterate string one by one

for i in str:

if i!= ‘ ’:

result +=i

print(“The given string after removing all spaces is: ”, result)

Output

Enter a string

Kendriya Vidyalaya

The given string after removing all spaces is: KendriyaVidyalaya

Result:

Thus, the program was executed successfully.


Practical No. 10

Objective:

10 To print personal information like Name, Father's Name, Class, School Name.

Source Code :

Name = input("Please Enter Your Name : ")

Father's Name = input("Please Enter Your Father's Name : ")

Class = int(input("Please Enter Class Number : "))

School Name = input("Please Enter Your School Name : ")

Output :

Please Enter Your Name : Arun

Please Enter Your Father's Name : Dinesh

Please Enter Your Class Number : 5

Please Enter Your School Name : Kendriya Vidayalaya AFS Avadi

Result:

Thus, the program was executed successfully.


Practical No. 11

Objective:

To print the following patterns using multiple print commands.

Source Code :

Simple pyramid pattern

# Simple Python program to print the Simple pyramid pattern

n = int(input("Enter the number of rows"))

# Here, we are declaring the integer variable to store the input rows

# Here, we are declaring an outer loop to handle number of rows

for i in range(0, n):

# Here, we are declaring an inner loop to handle number of columns

# Here, the values are changing according to outer loop

for j in range(0, i + 1):

# Here, we are declaring a for loop for printing stars

print("* ", end="")

# Here, we are giving the ending line after each row print()

Output :

Enter the number of rows: 5

**

***

****

Result:

Thus, the program was executed successfully.


Practical No. 12

Objective:

To calculate Simple interest if Principle amount = 2000, Rate_of_interest = 4.5, time


= 10

Source Code :

def simple_interest(p,t,r):

print('The principle is', p)

print('The time period is', t)

print('The rate of interest is',r)

si = (p * t * r)/100

print('The Simple Interest is', si)

return si

Output :

The Principle is 2000

The rate of interest is 4.5

The time period is 10

The Simple Interest is 900

Result:

Thus, the program was executed successfully.


Practical No. 13

Objective:

To print the table of 5 upto five terms.

Source Code :

num = 5

num = int(input("Display multiplication table of ? "))

Iterate 5 times from i = 1 to 5

for i in range(1, 5):

print(num, 'x', i, '=', num*i)

Output :

5*1=5

5 * 2 = 10

5 * 3 =15

5 * 4 = 20

5 * 5 = 25

Result:

Thus, the program was executed successfully.


Practical No. 14

Objective:

To convert Length given in kilometers into meters in Python.

Source Code :

kilometers = float(input("Please Enter the Kilometers = "))

meter = kilometers * 1000

print("%.2f Kilometers = %.2f Meters" %(kilometers, meter))

Output :

Please Enter the kilometers : 5

5.00 kilometers = 5000.00 metres

Result:

Thus, the program was executed successfully.


Practical No. 15

Objective:

To calculate square of a number 7.

Source Code :

# Declaring the number.

n=7

# Finding square by multiplying them

# with each other

square = n * n

# Printing square print(square)

Output :

49

Result:

Thus, the program was executed successfully.

You might also like