_ARTIFICIAL INTELLIGENCE project
_ARTIFICIAL INTELLIGENCE project
INTELLIGENCE
(CODE-417)
Introduction to Python:
Program#1
Learning Outcome: Basic Python Functions
INPUT:
#To print personal information like Name, Father’s Name,
Class and School Name
a= ‘Anish bagalkotker’
b= 'Gruraj bagalkotker'
c= 'Xth B'
OUTPUT:
Name of the student is Anish bagalkotker
Program#2
Learning Outcome: Basic Python Functions
INPUT:
#To find square of number 7
a=7
sq=a**2
OUTPUT:
Square of number 7 is 49
6
Program#3
Learning Outcome: Basic Python Functions
INPUT:
#To find the sum of two numbers 15 and 20
a=15
b=20
Sum=a+b
OUTPUT:
Sum of two numbers 15 and 20 is 35
7
Program#4
Learning Outcome: Basic Python Functions
INPUT:
#To convert length given in kilometers into meters
a=3
b=a*1000
OUTPUT:
Length in meters is 3000
8
Program#5
Learning Outcome: Basic Python Functions
INPUT:
#To convert hours into seconds
a=17
b=a*60*60
OUTPUT:
17 hours in seconds is 61200
9
Program#6
Learning Outcome: Basic Python Functions
INPUT
#To calculate Simple Interest if the principle_amount =
2000, rate_of_interest = 4.5 and time = 10
p=2000
r=4.5
t=10
s=(p*r*t)/100
OUTPUT:
Simple Interest is Rs. 900.0
10
PROGRAM#7
Learning Outcome: Python Arithmetic Operators
INPUT:
#To calculate Area and Perimeter of a rectangle
area=l*b
p=2*(l+b)
OUTPUT:
Enter the length in cm: 23
Program#8
Learning Outcome: Python Arithmetic Operators
INPUT:
#To calculate Area of a triangle with Base and Height
area=(1/2)*b*h
OUTPUT
Enter the length of base of triangle in cm: 33
Program#9
Learning Outcome: Python Arithmetic Operators
INPUT:
#To calculate average marks of 3 subjects
avg=(a+b+c)/3
OUTPUT
Enter the marks in First Subject: 95
Program#10
Learning Outcome: Python Arithmetic Operators
INPUT:
#To calculate discounted amount with discount %
d=l-s
dp=(l-s)/l*100
OUTPUT:
14
Program#11
Learning Outcome: Python Arithmetic Operators
INPUT:
#To calculate Surface Area and Volume of a Cuboid
vol=l*b*h
OUTPUT:
Enter the length of the cuboid in cm: 26
Program#12
Learning Outcome: Python Arithmetic Operators
INPUT:
#Program to check if a person can vote
if(a>=18):
else:
OUTPUT:
Case 1: Enter your age: 27 You are eligible to vote
Case 3: Enter your age: 16 No, you are not eligible to vote
17
Program#13
Learning Outcome: Python Arithmetic Operators
INPUT:
#To check the grade of a student
avg=(e+h+m+s+ss)/5
if(avg>90):
OUTPUT:
Case 1: Enter marks obtained in English: 95
18
elif(avg>80):
elif(avg>70):
elif(avg>60):
elif(avg>50):
else:
Program#14
Learning Outcome: Python Arithmetic Operators
INPUT:
#Input a number and check if the number is positive,
negative or zero and display an appropriate message
if(n<0):
elif(n>0):
else:
OUTPUT:
Case 1: Enter the number: 5.5 The number entered is
positive
Program#15
Learning Outcome: Python Arithmetic Operators
INPUT:
#Input a number and check if the number is positive,
negative or zero and display an appropriate message
if(n<0):
elif(n>0):
else:
OUTPUT:
23
Program#16
Learning Outcome: Python Arithmetic Operators
INPUT:
#To calculate the roots of Quadratic Equation by checking
the value of discriminant
d=b**2-4*a*c
if(d>0):
alpha=(-b+d**2-0.5)/(2*a)
beta=(-b-d**2-0.5)/(2*a)
25
elif(d==0):
alpha=(-b-d**2-1/2)/2*a
else:
OUTPUT:
Case 1: Enter the value of a: 3
Program#17
Learning Outcome: Python Arithmetic Operators
INPUT:
#To make menu based calculator to perform various
arithmetic calculations
while True:
print('''
if choice == 5:
break
if(choice==1):
elif(choice==2):
elif(choice==3):
else:
if(b!=0):
29
else:
else:
OUTPUT:
Case 1:
Case:2
Program#18
Learning Outcome: Python Arithmetic Operators
INPUT:
#To print first 10 natural numbers
n=1
for n in range(1,11):
print(n)
OUTPUT:
First 10 natural numbers are:
1 5 9
2 6 10
3 7
32
Program#19
Learning Outcome: Python Arithmetic Operators
INPUT:
#To print first 10 even numbers
n=2
count=0
while(count<10):
print(n)
n+=2
count+=1
OUTPUT:
First 10 even numbers are: 2 4 6 8 10 12 14 16
18 20
33
Program#20
Learning Outcome: Python Arithmetic Operators
INPUT:
#To print odd numbers from 1 to n
i=1
for i in range(i,n+1,2):
print(i)
OUTPUT:
Enter the number: 20
1 5 9 13 17 3 7
11 15 19
34
Program#20
Learning Outcome: Python Arithmetic Operators
INPUT:
#To print sum of first 10 natural numbers
n=1
s=0
while(n<=10):
s+=n
n+=1
OUTPUT:
Sum of first 10 natural numbers is 55
35
Program#21
Learning Outcome: Python Arithmetic Operators
INPUT:
#To print the table of 5
n=1
for n in range(1,11):
print('5 *',n,'=',n*5)
OUTPUT:
Following is the table of 5:
5*1=5 5 * 5 = 25 5 * 9 = 45
5 * 2 = 10 5 * 6 = 30 5 * 10 = 50
5 * 3 = 15 5 * 7 = 35
36
Program#22
Learning Outcome: Python Arithmetic Operators
INPUT:
#Program to find the sum of all numbers stored in a list
list=[5,6,9,12,17,15]
s=sum(list)
OUTPUT:
The sum of all numbers stored in the list is 64
37
Program#23
Learning Outcome: Python Arithmetic Operators
INPUT:
#Create a list in Python of children selected for science
quiz with following names- Arjun, Sonakshi, Vikram,
Sandhya, Sonal, Isha, Kartik Perform the following tasks
on the list in sequence
list=['Arjun','Sonakshi','Vikram','Sandhya','Sonal','Isha','Kar
tik']
print('Initial List:',list)
list.remove('Vikram')
list.append('Jay')
38
del list[2]
OUTPUT:
Initial List: ['Arjun', 'Sonakshi', 'Vikram', 'Sandhya', 'Sonal',
'Isha', 'Kartik']
Program#24
Learning Outcome: Python Arithmetic Operators
INPUT:
#Create a list List_1=[10,20,30,40]. Add the elements
[14,15,12] using extend function. Now sort the final list in
ascending order and print it
List_1=[10,20,30,40]
List_1.extend([14,15,12])
OUTPUT:
List after adding elements is [10, 20, 30, 40, 14, 15, 12]
Sorted list in ascending order is [10, 12, 14, 15, 20, 30, 40]
40
Program#25
Learning Outcome: Python Arithmetic Operators
INPUT:
#Write a program to add the elements of the two lists
import math
list1=[52,93,156,643,6]
list2=[75,93,96,16,4,55,1546]
list1.extend(list2)
OUTPUT:
41
Result after adding both the list is: [52, 93, 156, 643, 6, 75,
93, 96, 16, 4, 55, 1546]
Program#26
Learning Outcome: Python Arithmetic Operators
INPUT:
#Write a program to calculate mean, median and mode
using Numpy
import numpy as np
data = np.array([165, 26, 39, 42, 65, 69, 157, 26, 49, 160])
mean = np.mean(data)
median = np.median(data)
mode = np.bincount(data).argmax()
OUTPUT:
The given data is: [165 26 39 42 65 69 157 26 49 160]
43
Program#27
Learning Outcome: Python Arithmetic Operators
INPUT:
#Write a program to display line chart from (2,5) to (9,10)
import numpy as np
x_start, y_start = 2, 5
x_end, y_end = 9, 10
plt.plot(x, y)
plt.xlabel("X")
45
plt.ylabel("Y")
plt.title("Line Chart")
plt.show()
OUTPUT:
46
Program#28
Learning Outcome: Python Arithmetic Operators
INPUT:
#Write a program to display a scatter chart for the
following points (2,5), (9,10),(8,3),(5,7),(6,18)
x_coordinates = [2, 9, 8, 5, 6]
plt.scatter(x_coordinates, y_coordinates)
plt.xlabel("X")
plt.ylabel("Y")
plt.title("Scatter Plot")
plt.show()
47
OUTPUT:
48
Program#29
Learning Outcome: Python Arithmetic Operators
INPUT:
#Read CSV file saved in your system and display 10 rows
import pandas as pd
file_path = r“C:\Users\Home\Documents\country_full.csv”
df = pd.read_csv(file_path, encoding='latin1')
print(df.head(10))
OUTPUT:
49
Program#30
Learning Outcome: Python Arithmetic Operators
Task: Read CSV file saved in your system and display its
information.
INPUT:
#Write a program to display line chart from (2,5) to (9,10)
import numpy as np
x_start, y_start = 2, 5
x_end, y_end = 9, 10
plt.plot(x, y)
plt.xlabel("X")
50
plt.ylabel("Y")
plt.title("Line Chart")
plt.show()
OUTPUT: