Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

LAB REPORT#03

ARTIFICAL INTELLIGENCE
SUBMITTED TO: Sir Noman Ahmed
SUBMITTED BY: Muhammad Soban
REG NO.: FA19-BEE-145
DATE: 14 Oct,2021
IN-LAB(EXAMPLE’S)
Example-1:
Code:
class MyClass:
i = 12345
def f(self):
return 'hello world'
x = MyClass()
print (x.i)
print (x.f())

Result:

In this task we create a then define a function and then


create a object to call it.
Example-2:
Code:
class Complex:
def __init__(self, realpart, imagpart):
self.r = realpart
self.i = imagpart
x = Complex(3.0, -4.5)
print (x.r," ",x.i)

Result:

In this task we create a class and then define a function by


build-in function.
Example 3:
Code:
class Shape:

def __init__(self,x,y):

self.x = x

self.y = y

description = "This shape has not been described yet"

author = "Nobody has claimed to make this shape yet"

def area(self):

return self.x * self.y

def perimeter(self):

return 2 * self.x + 2 * self.y

def describe(self,text):

self.description = text

def authorName(self,text):

self.author = text

def scaleSize(self,scale):

self.x = self.x * scale

self.y = self.y * scale

a=Shape(3,4)

print (a.area())

print (a.perimeter())

Result:
Example 4:
Code:
class Shape:

def __init__(self,x,y):

self.x = x

self.y = y

description = "This shape has not been described yet"

author = "Nobody has claimed to make this shape yet"

def area(self):

return self.x * self.y

def perimeter(self):

return 2 * self.x + 2 * self.y

def describe(self,text):

self.description = text

def authorName(self,text):

self.author = text

def scaleSize(self,scale):

self.x = self.x * scale

self.y = self.y * scale

class Square(Shape):

def __init__(self,x):

self.x = x

self.y = x

class DoubleSquare(Square):

def __init__(self,y):

self.x = 2 * y
self.y = y

def perimeter(self):

return 2 * self.x + 3 * self.y

a=DoubleSquare(3)

print (a.area())

print (a.perimeter())

Result:

In this task we create a class(shape), then create another class


by name(square) and then one more class by name
(Doublesquare). In other words, we perform inheritance. Which
means to store first class object in 2nd class.
IN-LAB
Lab-Task 1:
Code:
class Basic_cal:
def __init__(self,x,y):
self.x = x
self.y = y

def add(self):
return self.x + self.y
def sub(self):
return self.x - self.y
def mul(self):
return self.x * self.y
def div(self):
return self.x / self.y

import math
class s_cal(Basic_cal):
def __init__(self,x,y):
self.x = x
self.y = y
def factorial(self):
return (math.factorial(self.x) , math.factorial(self.y))
def x_power_y(self):
return pow(self.x ,self.y)
def Log(self):
return (math.log(self.x) , math.log(self.y))
def ln(self):
return (math.log(self.x) , math.log(self.y))
a=s_cal(6,3)
print ('The sum is:',a.add())
print ('The factorial is:',a.factorial())
print ('The power is:',a.x_power_y())
print ('The log is:',a.Log())
print ('The natural log is:',a.ln())

Result:

In lab task we first create a class(basic_calc) for calculator to perform


addition, subtraction, division, multiplication. And then Create another
class inherited from basic_calc named s_calc which should have the
following additional methods; Factorial, x_power_y, log, ln.

You might also like