0% found this document useful (0 votes)
40 views

AI Prasun

Here are 3 patterns generated using nested loops: Pattern 1: * ** *** **** Pattern 2: * ** *** Pattern 3: 1 22 333 4444 The above patterns demonstrate the use of nested loops to generate different patterns by varying the loop conditions and print statements. Nested loops allow generating complex patterns by running one loop inside another.

Uploaded by

yashsehra000000
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)
40 views

AI Prasun

Here are 3 patterns generated using nested loops: Pattern 1: * ** *** **** Pattern 2: * ** *** Pattern 3: 1 22 333 4444 The above patterns demonstrate the use of nested loops to generate different patterns by varying the loop conditions and print statements. Nested loops allow generating complex patterns by running one loop inside another.

Uploaded by

yashsehra000000
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/ 12

PM SHRI KENDRIYA VIDYALAYA

SABARMATI

Name: - Prasun Kumar

Class: - 10-A

Roll no:- 10134


Page 1
PRACTICAL FILE

FOR CBSE 2023-24 EXAMINATION

[AS A PART OF THE ARTIFICIAL INTELLIGENCE COURSE (417)]

SUBMITTED BY: -

NAME: PRASUN KUMAR YADAV

SCHOOL ROLLNO: - 10134

UNDER THE GUIDANCE OF: Ms.Rashmika Ma’am


(COMPUTER INSTRUCTOR)

…………………………………….........................
Page 2
……………………………………………………...

PM SHRI KENDRIYA VIDYALAYA


SABARMATI

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)

Num1, Num2= Num2, Num1


print("After Swap:")
print("Num1: ", Num1)
print("Num2: ", Num2)

OUTPUT: Enter Number-1: 10


Enter Number-2: 20
Before Swap:
Num1: 10
Num2: 20
After Swap:
Num1: 20
Num2: 10

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)

Num1, Num2,Num3= Num2, Num3,Num1


print("After Swap:")
print("Num1: ", Num1)
print("Num2: ", Num2)
print("Num3: ", Num3)

OUTPUT: Enter Number-1: 10


Enter Number-2: 20
Enter Number-3: 30
Before Swap:
Num1: 10
Num2: 20
Num3: 30
After Swap:
Num1: 20
Num2: 30
Num3: 10

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')

OUTPUT: Enter the first number: 8


Enter thesecond number: 2
Enter the operator[/,*,+,-]: /
8.0 / 2.0 = 4.0

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')

OUTPUT: Enter the year: 2020


This year is 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)

Odd = int(input("Enter the input"))


total = 0
for number in range(1, Odd+1):
if(number % 2!=0):
print(number)
total = total + number
print("The sum of odd numbers", total)
OUTPUT:

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)

OUTPUT: Enter a Number : 123


The sum of the number is : 6

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")

OUTPUT: Please enter the character as you wish: A


the given character is a vowel

Please enter the character as you wish: s


the given character is a 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

OUTPUT: Enter The Number : 7


7x1=7
7 x 2 = 14
7 x 3 = 21
7 x 4 = 28
7 x 5 = 35
7 x 6 = 42
7 x 7 = 49
7 x 8 = 56
7 x 9 = 63
7 x 10 = 70

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

print('Sum of first' ,n,'terms: ',s)


OUTPUT: Enter the value of x: 3
Enter the value of n (for x**n): 6
Sum of first 6 terms: 1093.0

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)

OUTPUT: Enter 1st number: 3


Enter 2nd number: 5
Greatest Common Divisor (GCD) is 1
The Least Common Multiple (LCM) is 15

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)

# show pie plot


plt.show()

plt.bar(cars, data)
# show pie plot
plt.show()
OUTPUT:

………………………………………………………………………………………………………………………………………

Page 11

You might also like