0% found this document useful (0 votes)
47 views31 pages

AI Project

Uploaded by

anishbagalkotker
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views31 pages

AI Project

Uploaded by

anishbagalkotker
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 31

Introduction to Python:

Python is a programming language developed by Guido Van


Rossum and it first appeared on 20th February, 1991.
Python is an interpreted, object oriented, high-level programming
language. Python's simple, easy to learn syntax emphasizes
readability and therefore reduces the cost of program
maintenance.
Python is meant to be an easily readable language. Its formatting
is visually uncluttered, and it often uses English keywords where
other languages use punctuation. Unlike many other languages, it
does not use curly brackets to delimit blocks, and semicolons
after statements are allowed but are rarely, if ever, used. It has
fewer syntactic exceptions and special cases than C or Pascal.
There are many functions that get the work done in Python. If
someone is used to writing programs in other languages, Python
requires getting used to the functions, as the functions in Python
are more versatile. For example, the print() function in Python,
can print information in a variety of ways. A person may end the
printing in a certain way, separate items in a way, concatenate
text naturally, etc.
Program#1
Learning Outcome: Basic Python Functions
Objective: Using functions print() operations
Task: To print personal information like Name, Father’s Name,
Class and School Name.

INPUT:
#To print personal information like Name, Father’s Name, Class
and School Name
a= 'Mayank Narwal'
b= 'Sukhvinder Singh'
c= 'Xth A'
d= 'manav mangal SMART WORLD'
print('Name of the student is', a)
print('Name of the father is', b)
print('Class of the student is', c)
print('Name of the school is', d)

OUTPUT:
Name of the student is Mayank Narwal
Name of the father is Sukhvinder Singh
Class of the student is Xth A
Name of the school is manav mangal SMART WORLD
Program#2
Learning Outcome: Basic Python Functions
Objective: Using functions print() operations
Task: To find square of number 7.

INPUT:
#To find square of number 7
a=7
sq=a**2
print('Square of number 7 is ',sq)

OUTPUT:
Square of number 7 is 49
Program#3
Learning Outcome: Basic Python Functions
Objective: Using functions print() operations
Task: To find the sum of two numbers 15 and 20.

INPUT:
#To find the sum of two numbers 15 and 20
a=15
b=20
Sum=a+b
print('Sum of two numbers 15 and 20 is ',Sum)

OUTPUT:
Sum of two numbers 15 and 20 is 35
Program#4
Learning Outcome: Basic Python Functions
Objective: Using functions print() operations
Task: To convert length given in kilometers into meters.

INPUT:
#To convert length given in kilometers into meters
a=3
b=a*1000
print('Length in meters is ',b)

OUTPUT:
Length in meters is 3000
Program#5
Learning Outcome: Basic Python Functions
Objective: Using functions print() operations
Task: To convert hours into seconds.

INPUT:
#To convert hours into seconds
a=17
b=a*60*60
print(a,'hours in seconds is ',b)

OUTPUT:
17 hours in seconds is 61200
Program#6
Learning Outcome: Basic Python Functions
Objective: Using functions print() operations
Task: To calculate Simple Interest if the principle amount = 2000,
rate of interest = 4.5 and time = 10.
Attach your code here
Output
#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
print('Simple Interest is Rs.',s)
Simple Interest is Rs. 900.0
Program#7
Learning Outcome: Python Arithmetic Operators
Objective: Using functions input() operations
Task: To calculate Area and Perimeter of a rectangle.
Attach your code here
Output
#To calculate Area and Perimeter of a rectangle
l=int(input('Enter the length in cm: '))
b=int(input('Enter the breadth in cm: '))
area=l*b
p=2*(l+b)
print('Area of the rectangle is',area,'sq. cm')
print('Perimeter of the rectangle is',p,'cm')
Enter the length in cm: 23
Enter the breadth in cm: 15
Area of the rectangle is 345 sq. cm
Perimeter of the rectangle is 76 cm
Program#8
Learning Outcome: Python Arithmetic Operators
Objective: Using functions input() operations
Task: To calculate Area of a triangle with Base and Height.
Attach your code here
Output
#To calculate Area of a triangle with Base and Height
b=int(input('Enter the length of base of triangle in cm: '))
h=int(input('Enter the height of the triangle in cm: '))
area=(1/2)*b*h
print('The area of triangle is ',area,'sq. cm')
Enter the length of base of triangle in cm: 33
Enter the height of the triangle in cm: 25
The area of triangle is 412.5 sq. cm
Program#9
Learning Outcome: Python Arithmetic Operators
Objective: Using functions input() operations
Task: To calculate average marks of 3 subjects.
Attach your code here
Output
#To calculate average marks of 3 subjects
a=int(input('Enter the marks in First Subject: '))
b=int(input('Enter the marks in Second Subject: '))
c=int(input('Enter the marks in Third Subject: '))
avg=(a+b+c)/3
print('Average marks are ',avg)
area=(1/2)*b*h
print('The area of triangle is ',area)
Enter the marks in First Subject: 95
Enter the marks in Second Subject: 93
Enter the marks in Third Subject: 86
Average marks are 91.33333333333333
Program#10
Learning Outcome: Python Arithmetic Operators
Objective: Using functions input() operations
Task: To calculate discounted amount with discount %.
Attach your code here
Output
#To calculate discounted amount with discount %
l=int(input('Enter the list price Rs.'))
s=int(input('Enter the selling price Rs.'))
d=l-s
dp=(l-s)/l*100
print('Discounted amount is Rs.',d)
print('Discount percentage is ',dp,'%')
Enter the list price Rs.6000
Enter the selling price Rs.5700
Discounted amount is Rs. 300
Discount percentage is 5.0 %
Program#11
Learning Outcome: Python Arithmetic Operators
Objective: Using functions input() operations
Task: To calculate Surface Area and Volume of a Cuboid.
Attach your code here
Output
#To calculate Surface Area and Volume of a Cuboid
l=int(input('Enter the length of the cuboid in cm: '))
b=int(input('Enter the breadth of the cuboid in cm: '))
h=int(input('Enter the height of the cuboid in cm: '))
SA=2*(l*b + b*h + h*l)
vol=l*b*h
print('The surface area of cuboid is',SA,'cubic cm')
print('The volume of cuboid is',vol,'cubic cm')
Enter the length of the cuboid in cm: 26
Enter the breadth of the cuboid in cm: 22
Enter the height of the cuboid in cm: 13
The surface area of cuboid is 2392 cubic cm
The volume of cuboid is 7436 cubic cm
Program#12
Learning Outcome: Python Arithmetic Operators
Objective: Using functions if(), for(), while() operations
Task: Program to check if a person can vote.
Attach your code here
Output
#Program to check if a person can vote
a=int(input('Enter your age: '))
if(a>=18):
print('You are eligible to vote')
else:
print('No, you are not eligible to vote')
Case 1: Enter your age: 27 You are eligible to vote
Case 2: Enter your age: 18 You are eligible to vote
Case 3: Enter your age: 16 No, you are not eligible to vote
Program#13
Learning Outcome: Python Arithmetic Operators
Objective: Using functions if(), for(), while() operations
Task: To check the grade of a student.
Attach your code here
Output
#To check the grade of a student
e=int(input('Enter marks obtained in English: '))
h=int(input('Enter marks obtained in Hindi: '))
m=int(input('Enter marks obtained in Maths: '))
s=int(input('Enter marks obtained in Science: '))
ss=int(input('Enter marks obtained in Social Science: '))
avg=(e+h+m+s+ss)/5
if(avg>90):
Case 1: Enter marks obtained in English: 95
Enter marks obtained in Hindi: 86
Enter marks obtained in Maths: 98
Enter marks obtained in Science: 93
Enter marks obtained in Social Science: 97
You got A grade, Excellent
Case 2: Enter marks obtained in English: 83
Enter marks obtained in Hindi: 86
print('You got A grade, Excellent')
elif(avg>80):
print('You got B grade, Good job')
elif(avg>70):
print('You got C grade, Can score better')
elif(avg>60):
print('You got D grade, Needs improvement')
elif(avg>50):
print('You got E grade, You need to work hard')
else:
print('You have failed the examination')
Enter marks obtained in Maths: 84
Enter marks obtained in Science: 93
Enter marks obtained in Social Science: 85
You got B grade, Good job
Case 3: Enter marks obtained in English: 48
Enter marks obtained in Hindi: 43
Enter marks obtained in Maths: 42
Enter marks obtained in Science: 51
Enter marks obtained in Social Science: 47
You have failed the examination
Program#14
Learning Outcome: Python Arithmetic Operators
Objective: Using functions if(), for(), while() operations
Task: Input a number and check if the number is positive,
negative or zero and display an appropriate message.
Attach your code here
Output
#Input a number and check if the number is positive, negative or
zero and display an appropriate message
n=float(input('Enter the number: '))
if(n<0):
print('The number entered is negative')
elif(n>0):
print('The number entered is positive')
else:
print('The number entered is zero')
Case 1: Enter the number: 5.5 The number entered is positive
Case 2: Enter the number: -26 The number entered is negative
Case 3: Enter the number: 0 The number entered is zero
Program#15
Learning Outcome: Python Arithmetic Operators
Objective: Using functions if(), for(), while() operations
Task: Input a number and check if the number is positive,
negative or zero and display an appropriate message.
Attach your code here
Output
#Input a number and check if the number is positive, negative or
zero and display an appropriate message
n=float(input('Enter the number: '))
if(n<0):
print('The number entered is negative')
elif(n>0):
print('The number entered is positive')
else:
print('The number entered is zero')
Case 1: Enter the number: 5.5 The number entered is positive
Case 2: Enter the number: -26 The number entered is negative
Case 3: Enter the number: 0 The number entered is zero
Program#16
Learning Outcome: Python Arithmetic Operators
Objective: Using functions if(), for(), while() operations
Task: To calculate the roots of Quadratic Equation by checking
the value of discriminant.
Attach your code here
Output
#To calculate the roots of Quadratic Equation by checking the
value of discriminant
a=int(input('Enter the value of a: '))
b=int(input('Enter the value of b: '))
c=int(input('Enter the value of c: '))
d=b**2-4*a*c
if(d>0):
print('It has real and distinct roots')
Case 1: Enter the value of a: 3
Enter the value of b: 5
Enter the value of c: 2
It has real and distinct roots
The roots are -0.75 and -1.0833333333333333
Case 2: Enter the value of a: 4
Enter the value of b: 4
Enter the value of c: 1
It has real and same roots
The roots are -9.0 and -9.0
alpha=(-b+d**2-0.5)/(2*a)
beta=(-b-d**2-0.5)/(2*a)
print('The roots are',alpha,'and',beta)
elif(d==0):
print('It has real and same roots')
alpha=(-b-d**2-1/2)/2*a
print('The roots are',alpha,'and',alpha)
else:
print('It has no real roots')
Case 3: Enter the value of a: 6
Enter the value of b: 3
Enter the value of c: 1
It has no real roots
Program#17
Learning Outcome: Python Arithmetic Operators
Objective: Using functions if(), for(), while() operations
Task: To make menu based calculator to perform various
arithmetic calculations.
Attach your code here
Output
#To make menu based calculator to perform various arithmetic
calculations
while True:
print('''
Press 1 for Addition
Press 2 for Subtraction
Press 3 for Multiplication
Press 4 for Division and Remainder
Press 5 to Exit the program''')
choice = int(input('Enter your choice: '))
Press 1 for Addition
Press 2 for Subtraction
Press 3 for Multiplication
Press 4 for Division and Remainder
Press 5 to Exit the program
Enter your choice: 3
Enter the first number: 35
Enter the second number: 60
Product of two numbers is 2100.0
if choice == 5:
print('You exited the program')
break
elif(choice>=1 and choice<=4):
a = float(input('Enter the first number: '))
b = float(input('Enter the second number: '))
if(choice==1):
print('Sum of two numbers is ',a+b)
elif(choice==2):
print('Difference of two numbers is ',a-b)
elif(choice==3):
print('Product of two numbers is ',a*b)
else:
if(b!=0):
Press 1 for Addition
Press 2 for Subtraction
Press 3 for Multiplication
Press 4 for Division and Remainder
Press 5 to Exit the program
Enter your choice: 4
Enter the first number: 77
Enter the second number: 0
Division by zero is not defined
Press 1 for Addition
Press 2 for Subtraction
Press 3 for Multiplication
Press 4 for Division and Remainder
Press 5 to Exit the program
print('Quotient of two numbers is ',a//b)
print('Remainder of two numbers is ',a%b)
else:
print('Division by zero is not defined')
else:
print('Invalid choice! Please enter a valid choice.')
Enter your choice: 5
You exited the program
Program#18
Learning Outcome: Python Arithmetic Operators
Objective: Using functions if(), for(), while() operations
Task: To print first 10 natural numbers.
Attach your code here
Output
#To print first 10 natural numbers
n=1
print('First 10 natural numbers are:')
for n in range(1,11):
print(n)
First 10 natural numbers are:
1
2
3
4
5
6
7
8
9
10
Program#19
Learning Outcome: Python Arithmetic Operators
Objective: Using functions if(), for(), while() operations
Task: To print first 10 even numbers.
Attach your code here
Output
#To print first 10 even numbers
n=2
count=0
print('First 10 even numbers are:')
while(count<10):
print(n)
n+=2
count+=1
First 10 even numbers are:
2
4
6
8
10
12
14
16
18
20
Program#20
Learning Outcome: Python Arithmetic Operators
Objective: Using functions if(), for(), while() operations
Task: To print odd numbers from 1 to n.
Attach your code here
Output
#To print odd numbers from 1 to n
n=int(input('Enter the number: '))
i=1
print('Odd numbers from 1 to',n,'are:')
for i in range(i,n+1,2):
print(i)
Enter the number: 20
Odd numbers from 1 to 20 are:
1
3
5
7
9
11
13
15
17
19
Program#20
Learning Outcome: Python Arithmetic Operators
Objective: Using functions if(), for(), while() operations
Task: To print sum of first 10 natural numbers.
Attach your code here
Output
#To print sum of first 10 natural numbers
n=1
s=0
while(n<=10):
s+=n
n+=1
print('Sum of first 10 natural numbers is',s)
Sum of first 10 natural numbers is 55
Program#21
Learning Outcome: Python Arithmetic Operators
Objective: Using functions if(), for(), while() operations
Task: To print the table of 5.
Attach your code here
Output
#To print the table of 5
n=1
print('Following is the table of 5:')
for n in range(1,11):
print('5 *',n,'=',n*5)
Following is the table of 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
Program#22
Learning Outcome: Python Arithmetic Operators
Objective: Using functions list() operations
Task: Program to find the sum of all numbers stored in a list.
Attach your code here
Output
#Program to find the sum of all numbers stored in a list
list=[5,6,9,12,17,15]
s=sum(list)
print('The sum of all numbers stored in the list is',s)
The sum of all numbers stored in the list is 64
Program#23
Learning Outcome: Python Arithmetic Operators
Objective: Using functions list() operations
Task: 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.
Attach your code here
Output
#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','Kartik']
print('Initial List:',list)
list.remove('Vikram')
print('List after removing Vikram:',list)
Initial List: ['Arjun', 'Sonakshi', 'Vikram', 'Sandhya', 'Sonal', 'Isha',
'Kartik']
List after removing Vikram: ['Arjun', 'Sonakshi', 'Sandhya', 'Sonal',
'Isha', 'Kartik']
List after adding Jay at the end: ['Arjun', 'Sonakshi', 'Sandhya',
'Sonal', 'Isha', 'Kartik', 'Jay']
List after removing second item: ['Arjun', 'Sonakshi', 'Sonal',
'Isha', 'Kartik', 'Jay']
list.append('Jay')
print('List after adding Jay at the end:',list)
del list[2]
print('List after removing second item:',list)
Program#24
Learning Outcome: Python Arithmetic Operators
Objective: Using functions list() operations
Task: 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.
Attach your code here
Output
#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])
print("List after adding elements is",List_1)
List_1.sort()
print("Sorted list in ascending order is",List_1)
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]
Program#25
Learning Outcome: Python Arithmetic Operators
Objective: Using functions list() operations
Task: Write a program to add the elements of the two lists.
Attach your code here
Output
#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]
print('First list is:',list1)
print('Secons list is:',list2)
list1.extend(list2)
print('Result after adding both the list is:',list1)
print('The sum of the list is:',sum(list1))
First list is: [52, 93, 156, 643, 6]
Secons list is: [75, 93, 96, 16, 4, 55, 1546]
Result after adding both the list is: [52, 93, 156, 643, 6, 75, 93,
96, 16, 4, 55, 1546]
The sum of the list is: 2835
Program#26
Learning Outcome: Python Arithmetic Operators
Objective: Using libraries
Task: Write a program to calculate mean, median and mode
using Numpy.
Attach your code here
Output
#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()
print("The given data is:", data)
The given data is: [165 26 39 42 65 69 157 26 49 160]
Mean of the given data is: 79.8
Median of the given data is: 57.0
Mode of the given data is: 26
print("Mean of the given data is:", mean)
print("Median of the given data is:", median)
print("Mode of the given data is:", mode)
Program#27
Learning Outcome: Python Arithmetic Operators
Objective: Using libraries
Task: Write a program to display line chart from (2,5) to (9,10).
Attach your code here
#Write a program to display line chart from (2,5) to (9,10)
import matplotlib.pyplot as plt
import numpy as np
x_start, y_start = 2, 5
x_end, y_end = 9, 10
x = np.linspace(x_start, x_end, 100)
y = (y_end - y_start) / (x_end - x_start) * (x - x_start) + y_start
plt.plot(x, y)
plt.xlabel("X")
plt.ylabel("Y")
plt.title("Line Chart")
plt.show()
Output
Program#28
Learning Outcome: Python Arithmetic Operators
Objective: Using libraries
Task: Write a program to display a scatter chart for the following
points (2,5), (9,10),(8,3),(5,7),(6,18).
Attach your code here
#Write a program to display a scatter chart for the following points
(2,5), (9,10),(8,3),(5,7),(6,18)
import matplotlib.pyplot as plt
x_coordinates = [2, 9, 8, 5, 6]
y_coordinates = [5, 10, 3, 7, 18]
plt.scatter(x_coordinates, y_coordinates)
plt.xlabel("X")
plt.ylabel("Y")
plt.title("Scatter Plot")
plt.show()
Output
Program#29
Learning Outcome: Python Arithmetic Operators
Objective: Using libraries
Task: Read CVS file saved in your system and display 10 rows.
Attach your code here
#Read CVS file saved in your system and display 10 rows
import pandas as pd
file_path = r'C:\Users\itcar\Documents\Python Scripts\
GamingStudy_data.csv\GamingStudy_data.csv'
df = pd.read_csv(file_path, encoding='latin1')
print(df.head(10))
Output
S. No. Timestamp GAD1 ... SPIN_T Residence_ISO3
Birthplace_ISO3
0 1 42052.00437 0 ... 5.0 USA USA
1 2 42052.00680 1 ... 33.0 USA USA
2 3 42052.03860 0 ... 31.0 DEU DEU
3 4 42052.06804 0 ... 11.0 USA USA
4 5 42052.08948 2 ... 13.0 KOR USA
5 6 42052.13119 0 ... 13.0 USA USA
6 7 42052.14622 0 ... 26.0 USA USA
7 8 42052.15930 0 ... NaN JPN USA
8 9 42052.19737 2 ... 55.0 USA USA
9 10 42052.22995 2 ... 26.0 FIN FIN
[10 rows x 55 columns]
Program#30
Learning Outcome: Python Arithmetic Operators
Objective: Using libraries
Task: Read CVS file saved in your system and display its
information.
Attach your code here
#Write a program to display line chart from (2,5) to (9,10)
import matplotlib.pyplot as plt
import numpy as np
x_start, y_start = 2, 5
x_end, y_end = 9, 10
x = np.linspace(x_start, x_end, 100)
y = (y_end - y_start) / (x_end - x_start) * (x - x_start) + y_start
plt.plot(x, y)
plt.xlabel("X")
plt.ylabel("Y")
plt.title("Line Chart")
plt.show()
Output

You might also like