0% found this document useful (0 votes)
3 views18 pages

Ai Lab Manual PDF

The document includes acknowledgments to a principal, a teacher, and family for support in a project on Artificial Intelligence. It contains a series of Python code snippets demonstrating various programming concepts such as input handling, conditional statements, loops, and calculations. Each code snippet is accompanied by example inputs and expected outputs.

Uploaded by

aradhymishra34
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)
3 views18 pages

Ai Lab Manual PDF

The document includes acknowledgments to a principal, a teacher, and family for support in a project on Artificial Intelligence. It contains a series of Python code snippets demonstrating various programming concepts such as input handling, conditional statements, loops, and calculations. Each code snippet is accompanied by example inputs and expected outputs.

Uploaded by

aradhymishra34
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/ 18

ACKNOWLEDGEMENT

I extend my sincere thanks to my principal


Ms. Neeru Bhaskar ma'am for her support and
for all the facilities provided for the
preparation of this project work.

I would like to express my gratitude to my


Al teacher Ms. Rashmi Srivastava for giving
me the opportunity to undertake this
research project and further my education in
field of Artificial Intelligence.

I am also grateful to my family for their


constant support.
AI LAB MANUAL

CODE 1. a = int(input("Please Enter


no. 1")) b = int(input("Please enter
no. 2")) c = a a = b b = c print("The
no. 1 is", a) print("The no. 2 is",
b)

Input:
Please Enter no. 1: 3
Please enter no. 2: 7

Output: The
no. 1 is 7 The
no. 2 is 3
CODE 2.
num= int(input("Enter a Number: "))
if num == 0:
print("Number is zero.")
elif num < 0:
print("Number is negative.")
else:
print("Number is positive.")

Input:
Enter a Number: 0

Output:
Number is zero.
CODE 3.

F = int(input("Enter temperature in
Fahrenheit: "))
C = (F - 32) * 5/9
C = round(C, 2)
print(f"Temperature in Fahrenheit is: {C}")

Input:
Enter temperature in Fahrenheit: 98

Output:
Temperature in Fahrenheit is: 36.67
CODE 4:

r = int(input("Enter Radius (in cm): "))


area = 22/7 *r * r
print(f"Area in cm is: {area}")

Input:
Enter Radius (in cm): 7

Output:
Area in cm is: 154.0
CODE 5.

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


square= num * num
print(f"Square of number {num} is {square}.")

Input:
Enter number: 5

Output:
Square of number 5 is 25.
Code 6.

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


if num % 2==0:
print("Number is Even.")
else:
print("Number is Odd.")

Input:
Enter Number: 4

Output:
Number is Even.
CODE 7.

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


factor= 0
for i in range(1, num+1):
if num%i==0:
factor +=1
if factor <=2:
print("Number is Prime.")
else:
print("Number is not Prime.")

Input:
Enter Number: 2

Output:
Number is Prime.
CODE 8.

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


if num % 4 ==0:
print("Number is leap year.")
else:
print("Number is not leap year.")

Input:
Enter number: 2024

Output:
Number is leap year.
CODE 9.

n = int(input("Enter number: "))


a=0
for i in range(1, n+1):
a+=i
print(f"Sum of first {n} natural numbers is:
{a}.")

Input:
Enter number: 5

Output:
Sum of first 5 natural numbers is: 15.
CODE 10.

Num = int(input("Enter Number: "))


a = 0 for i in range(1, 11): a =
Num * i {a}") print(f"{Num} X {i} =

Input: Enter Number: 4

Output:

4 X 1 = 4 4 X 2 = 8 4 X 3 = 12 4 X
4 = 16 4 X 5 = 20 4 X 6 = 24 4 X 7
= 28 4 X 8 = 32 4 X 9 = 36 4 X 10 =
40
Code 11.

Num1 = int(input("Enter Number 1: ")) Num2


= int(input("Enter Number 2: ")) if
Num1 > Num2: print(f"{Num1} is greater
than {Num2}.") elif Num1 < Num2:
print(f"{Num2} is greater than {Num1}.")
else: print(f"{Num1} is equal to
{Num2}.")

Input: Enter Number 1: 8 Enter Number 2:


5

Output: 8 is greater than 5.


CODE 12.

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


factorial = 1
for i in range(1, num + 1):
factorial *= i
print(f"The factorial of {num} is {factorial}")

Input:
Enter Number: 5

Output:
The factorial of 5 is 120
CODE 13.

a = str(input("Enter String: "))


a = a.lower()
vowels = ['a', 'e', 'i', 'o', 'u']
vowel = 0
consonant = 0
for i in a:
if i in vowels:
vowel+=1
else:
consonant+=1
print(f'No. of vowels: {vowel} \nNo. of
consonants: {consonant} ')

Input:
Enter String: Hello

Output:

No. of vowels: 2
No. of consonants: 3
CODE 14.

for i in range(1,11):
for a in range(1,11):
print('*'*a)

Output:

* ** *** **** *****


****** *******
******** *********
**********
CODE 15.

rows = int(input("Enter no. of rows: "))

for i in range(rows): for a in


range(i+1): print(a+1, end="") print()

Input: Enter no. of rows: 5

Output:

1 12 123 1234 12345

You might also like