AI Prasun
AI Prasun
SABARMATI
Class: - 10-A
SUBMITTED BY: -
…………………………………….........................
Page 2
……………………………………………………...
DEPARTMENT OF ARTIFICIAL
INTELLIGENCE
CERTIFICATE
This is to certify that Master. Prasun Kumar Yadav a
student of class X-A ,School Rollno:10134 has
successfully completed the Practical file for CBSE
EXAMINATION under the guidance of Ms. Rashmika
Ma’am,(Computer Instructor) during the year 2023-
2024.
DATE :- …………………………
Subject Teacher’s Signature :- ………………………..
Page 3
PRACTICAL NO: 1
OBJECTIVE Write a program to input two numbers and swap them.
SOURCE Num1=int(input("Enter Number-1: "))
CODE: Num2=int(input("Enter Number-2: "))
print("Before Swap: ")
print("Num1: ", Num1)
print("Num2: ", Num2)
PRACTICAL NO: 2
OBJECTIVE Write a program to input three numbers and swap them as this: 1st number becomes 2nd
number 2nd number becomes 3rd number and 3rd number becomes 1st number.
SOURCE Num1=int(input("Enter Number-1: "))
CODE: Num2=int(input("Enter Number-2: "))
Num3=int(input("Enter Number-3: "))
print("Before Swap: ")
print("Num1: ", Num1)
print("Num2: ", Num2)
print("Num3: ", Num3)
Page 4
PRACTICAL NO: 3
OBJECTIVE Write a program that reads two numbers and an arithmetic operator and displays the
computed result.
SOURCE a=float(input('Enter the first number: '))
CODE: b=float(input('Enter the second number: '))
c=input('Enter the operator[/,*,+,-]: ')
if c=='/':
r=a/b
print(a,c,b,'=',r)
elif c=='*':
r=a*b
print(a,c,b,'=',r)
elif c=='+':
r=a+b
print(a,c,b,'=',r)
elif c=='-':
r=a-b
print(a,c,b,'=',r)
else:
print('Invalid operator')
PRACTICAL NO: 4
OBJECTIVE Write a program to accept the year and check if it is a leap year or not.
SOURCE a=int(input('Enter the year:'))
CODE: if a%4==0:
print('This year is a leap year')
else:
print('This year is not a leap year')
PRACTICAL NO: 5
OBJECTIVE Write a program to find largest among three integers. Make use of if -else statement.
SOURCE a=int(input('Enter the first integer:'))
CODE: b=int(input('Enter the second integer:'))
c=int(input('Enter the third integer:'))
if a>b and a>c:
print(a, 'is the largest integer')
if b>a and b>c:
print(b, 'is the largest integer')
if c>a and c>b:
print(c, 'is the largest integer')
else:
print(‘All or any two are equal')
OUTPUT: Enter the first integer:56
Enter the second integer:34
Enter the third integer:67
67 is the largest integer.
Page 5
PRACTICAL NO: 6
OBJECTIVE Write a program to calculate and print the sum of even and odd integers of the first n
natural numbers.
SOURCE Even = int(input("Enter the input"))
CODE: total = 0
for number in range(1, Even+1):
if(number % 2 == 0):
print(number)
total = total + number
print("The sum of even numbers", total)
PRACTICAL NO: 7
OBJECTIVE Write a program to input a number and print the sum of digits in the given number.
SOURCE n = int(input("Enter a Number : "))
CODE: sum = 0
while (n != 0):
sum = sum + (n % 10)
n = n//10
print(sum)
PRACTICAL NO: 8
OBJECTIVE Write a program to accept a character from the user and display whether it is vowel or consonant.
SOURCE ch=input("Please enter the character as you wish: ")
CODE: if(ch== 'a'or ch== 'A'or ch== 'e'or ch== 'E'or ch== 'i' or ch=='I' or ch=='o' or ch=='O' or ch=='u' or ch=='U'):
print("The given character ",ch," is the vowel")
else:
print("The given character ",ch," is the consonant")
Page 6
PRACTICAL NO: 9
OBJECTIVE
SOURCE x = int(input("Enter the month number: "))
CODE: if (x==1):
print ("January")
if (x==2):
print("February")
if (x==3):
print("March")
if (x==4):
print("April")
if (x==5):
print("May")
if (x==6):
print("June")
if (x==7):
print("July")
if (x==8):
print("August")
if(x==9):
print("September")
if(x==10):
print("October")
if(x==11):
print("November")
if(x==12):
print("December")
if(x<1 or x>12):
print("Invalid input")
OUTPUT: Case 1:
Enter the month number: 1
Jan
Case 2:
Enter the month number: 6
June
Case 3:
Enter the month number: 13
Invalid input
Case 4:
Enter the month number: -10
Invalid input
Page 7
PRACTICAL NO: 10
OBJECTIVE Write a program to input a number and display the table of that number.
SOURCE n=int(input("Enter The Number : "))
CODE: i=1
while(i<=10):
t=n*i
print(n,"x",i,"=",t)
i=i+1
PRACTICAL NO: 11
OBJECTIVE Write a program to enter a number and check if its prime or not.
SOURCE n = int(input("Enter The Number : "))
CODE: # Check if the number is greater than 1
if n > 1:
for i in range(2, int(n/2)+1):
if (n % i) == 0:
print(num, "is not a prime number")
break
else:
print(n, "is a prime number")
# If the number is less than 1, its also not a prime number.
else:
print(n, "is not a prime number")
OUTPUT:
5 is a prime number
Page 8
PRACTICAL NO: 12
OBJECTIVE Write a Program to generate the following patterns using nested loops.
SOURCE row = int(input("Enter the number of rows : "))
CODE: print("Pattern -1 ")
for i in range(0, row + 1, 1):
for j in range(1, i + 1):
print('*', end=' ')
print("")
print("Pattern -2 ")
for i in range(0, row + 1, 1):
for j in range(1, 5-i+1 ):
print(j, end=' ')
print("")
print("Pattern -3 ")
for i in range(0, row + 1, 1):
for j in range(65, 65+i ):
print(chr(j), end=' ')
print("")
OUTPUT: Pattern -1 Pattern -2 Pattern -3
Enter the number of rows : 5 Enter the number of rows : 5 Enter the number of rows : 5
12345
* 1234 A
* * 123 A B
* ** 12 A BC
* *** 1 A BCD
* **** A BCDE
Page 9
PRACTICAL NO: 13
OBJECTIVE Write a program to find sum of series : s=1+x+x²+x³+x⁴…+xⁿ
SOURCE x=float(input('Enter the value of x: '))
CODE: n=int(input('Enter the value of n (for x**n): '))
s=0
for a in range(n+1):
s+=x**a
PRACTICAL NO: 14
OBJECTIVE Write a program in python to compute the Greatest Common Divisor and Least Common
Multiple of two integers.
SOURCE # GCD PROGRAM
CODE: num1 = int(input("Enter 1st number: "))
num2 = int(input("Enter 2nd number: "))
i=1
while(i <= num1 and i <= num2):
if(num1 % i == 0 and num2 % i == 0):
gcd = i
i=i+1
print("Greatest Common Divisor (GCD) is ", gcd)
# LCM PROGRAM
if num1 > num2:
greater = num1
else:
greater = num2
while(True):
if((greater % num1 == 0) and (greater % num2 == 0)):
lcm = greater
break
greater += 1
print("The Least Common Multiple (LCM) is ", lcm)
Page 10
PRACTICAL NO: 15
OBJECTIVE Write a program in python to visualization plots bar and pie chart using matplotlib library.
[Hint: first from cmd prompt> pip install matplotlib]
SOURCE # Import libraries
CODE: from matplotlib import pyplot as plt
import numpy as np
# Creating dataset
cars = ['AUDI', 'BMW', 'FORD', 'TESLA', 'JAGUAR', 'MERCEDES']
data = [23, 17, 35, 29, 12, 41]
# Creating plot
fig = plt.figure(figsize =(10, 7))
plt.pie(data, labels = cars)
plt.bar(cars, data)
# show pie plot
plt.show()
OUTPUT:
………………………………………………………………………………………………………………………………………
Page 11