[go: up one dir, main page]

0% found this document useful (0 votes)
23 views14 pages

X A AI Project File

The document is a practical file for an Artificial Intelligence course at Bal Bharati Public School for the year 2022-23, containing various programming exercises. It includes code snippets for calculating factorials, checking odd or even numbers, identifying prime numbers, and more. Each section provides a problem statement followed by the corresponding Python code and sample output.

Uploaded by

harshraj509.2020
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)
23 views14 pages

X A AI Project File

The document is a practical file for an Artificial Intelligence course at Bal Bharati Public School for the year 2022-23, containing various programming exercises. It includes code snippets for calculating factorials, checking odd or even numbers, identifying prime numbers, and more. Each section provides a problem statement followed by the corresponding Python code and sample output.

Uploaded by

harshraj509.2020
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/ 14

Bal Bharati Public School, I.

P Yojna
Year : 2022-23

Name :
Class : XA
Roll No. : 10120

File :
Artificial Intelligence Practical File
CONTENTS
1. Factorial
2. Odd or even
3. Prime numbers
4. Tables
5. Highest between 3 numbers
6. Armstrong
7. Palindrome
8. Nested if else
9. For Loop
10. While Loop
11. Perfect Square
12. Conversion
13. Relational Operators
14. If Else
15. Finding Cube
1. Factorial
#WAP to find factorial of a number between 1 to 7

for i in range(1,8,1):

fact=1

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

fact=fact*j

print("the factorial of",i,"=",fact)

>> the factorial of 1 = 1

the factorial of 2 = 2

the factorial of 3 = 6

the factorial of 4 = 24

the factorial of 5 = 120

the factorial of 6 = 720

the factorial of 7 = 5040

2. Odd or Even
# WAP to find whether a number is odd or even
n=int(input("enter the number -"))
if n%2!=0:
print("Number is odd")
else:
print("Number is Even")
>> enter the number - 44
Number is Even
3. Prime Numbers
# WAP to find whether a number is prime or not

n=int(input("enter the number -"))

k=0

if n==0 or n==1:

print("Number is neither Prime nor composite")

elif n==2:

print("Number is Smallest and Even Prime Number")

else:

for i in range(2,n,1):

if n%i==0:

k=k+1

if k==0:

print("number is Prime")

else:

print("number is not prime")

>> enter the number - 7

number is Prime

4. Tables
# WAP to input a number and write its table till
10.

num = int(input("Enter the number :: " ))


print(num , "* 1 = ", num* 1)

print(num , "* 2 = ", num* 2)

print(num , "* 3 = ", num* 3)

print(num , "* 4 = ", num* 4)

print(num , "* 5 = ", num* 5)

print(num , "* 6 = ", num* 6)

print(num , "* 7 = ", num* 7)

print(num , "* 8 = ", num* 8)

print(num , "* 9 = ", num* 9)

print(num , "* 10 = ", num* 10)

>> Enter the number :: 5

5 * 1 = 5

5 * 2 = 10

5 * 3 = 15

5 * 4 = 20

5 * 5 = 25

5 * 6 = 30

5 * 7 = 35

5 * 8 = 40

5 * 9 = 45

5 * 10 = 50

5. Highest between 3 numbers


#WAP to find the greater number between 3 numbers

a=int(input("Enter the value for a"))

b=int(input("enter the value for b"))

c=int(input("enter the value for c"))

if a>b:

if a>c:

print("a is Greater")

else:

print("C is greater")

else:

if b>c:

print("b is greater")

else:

print("c is greater")

>> Enter the value for a - 56

enter the value for b - 78

enter the value for c - 34

b is greater

6. Armstrong
# WAP to find whether a number is an Armstrong or
not

num = int(input("Enter a Number:"))

order = len(str(num))
temp = num;

sum = 0

while(temp>0):

digit =temp%10

sum += digit **order

temp = temp//10

if(sum==num):

print("",num,"is an Armstrong number")

else:

print("",num,"is not an Armstrong number")

>> Enter a Number: 371

371 is an Armstrong number

7. Palindrome
# WAP to find whether a number is palindrome or
not

n=int(input("enter the number"))

rev=0

p=n

while n>0:

r=n%10

n=n//10

rev=rev*10+r

if p==rev:
print("number is palindrome")

else:

print("number is Not palindrome"

>> enter the number 121

number is palindrome

8. Nested if else
# WAP to print grades as per the given percentage
by the user

p=int(input("Enter the percentage -"))

if p>=33:

if p>=45:

if p>=60:

if p>=75:

if p>=80:

if p>=90:

if p>100:

print("Invalid")

else:

print("A++")

else:

print("A+")

else:

print("A")
else:

print("B")

else:

print("C")

else:

print("Try Again")

>> Enter the percentage - 89

A+

9. For Loop
# WAP to print odd numbers between 5 to 20

for i in range(5,20,1):

if i%2!=0:

print(i)

>> 5

11

13

15

17

19

21
10. While Loop
# WAP to find the reverse of a number

print("Enter the number -")

n=int(input())

rev=0

while n>0:

rem=n%10

n=n//10

rev=rev*10+rem

print("The Reverse of number=",rev)

>> Enter the number - 45

The Reverse of number= 54

11. Perfect Square


# WAP to find the number given by user
import math
# Taking the input from user
number = int(input("Enter the Number -"))
root = math.sqrt(number)
if int(root + 0.5) ** 2 == number:
print(number, "is a perfect square")
else:
print(number, "is not a perfect square")
>> Enter the Number – 36
36 is a perfect square

12. Conversion
height = float(input("Enter your height in
centimeters :: "))

heightininch = height / 2.54

print(heightininch)

heightinch = float(input("Enter your height in


inches upto one decimal mark shown above = "))

heightinfeets = heightinch / 12

print(heightinfeets)

>> Enter your height in centimeters :: 157

61.811023622047244

Enter your height in inches upto one decimal


mark shown above = 61.8

5.1499999999999995

13. Relational Operators


# WAP to input the age if age is equals to or
greater than 18 then print ‘YOU CAN VOTE’

age = int(input("Enter your age - "))

if (age>18 and age<=100):

print("YOU CAN VOTE")

>> Enter your age - 20

YOU CAN VOTE


14. If Else
# WAP to input your mood. If mood is sad then
print one joke. Otherwise print two jokes

mood = input("Enter your mood - " )

if mood =="Sad" or mood =="sad":

print("Why can't elephants use computers?")

print("Because they are scared of the mouse


"v")
:-

else:

print("Rohan threw his clock out of the window.


Do you know why........because he wanted to see
time fly ● v")
"
-
:

print("Do you know the prize recieved by the


person who invented knock-knock joke? He won the
no-bell prize! ● :")
-
v
"

>> Enter your mood - excited

Rohan threw his clock out of the window. Do you


know why........because he wanted to see time fly
"
-
:●
v

Do you know the prize recieved by the person who


invented knock-knock joke? he won the no-bell
prize! ● :
-
v
"

15. Finding Cube


# WAP to find the cube of a number given by user

num = int(input("Enter the number :: "))

cube = num**3
print(cube)

>> Enter the number :: 12

1728

Submitted to:
Ms. Preeti Nagar

You might also like