0% found this document useful (0 votes)
28 views5 pages

Lab Experiment No 9-Gcr

The document discusses programming concepts using classes in Python. It includes four examples: 1) Defining a VelocityProfile class to calculate fluid velocity based on position. 2) Defining a cal class to perform basic math operations like addition, subtraction etc. on user inputs. 3) Defining a sub class to generate all possible subsets of a set of distinct integers. 4) Defining a check class to append, delete, and display elements of a list.
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)
28 views5 pages

Lab Experiment No 9-Gcr

The document discusses programming concepts using classes in Python. It includes four examples: 1) Defining a VelocityProfile class to calculate fluid velocity based on position. 2) Defining a cal class to perform basic math operations like addition, subtraction etc. on user inputs. 3) Defining a sub class to generate all possible subsets of a set of distinct integers. 4) Defining a check class to append, delete, and display elements of a list.
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/ 5

Lab 9a): Programming on class

class VelocityProfile:

def __init__(self, beta, mu0, n, R):

self.beta, self.mu0, self.n, self.R = \

beta, mu0, n, R

def value(self, r):

beta, mu0, n, R = \

self.beta, self.mu0, self.n, self.R

n = float(n) # ensure float divisions

v = (beta/(2.0*mu0))**(1/n)*(n/(n+1))*(R**(1+1/n) - r**(1+1/n))

return v

v = VelocityProfile(R=1, beta=0.06, mu0=0.02, n=0.1)

print (v.value(r=0.1))

Lab 9b): Programming on class-Calculator

class cal():

def __init__(self,a,b):

self.a=a

self.b=b

def add(self):

return self.a+self.b

def mul(self):
return self.a*self.b

def div(self):

return self.a/self.b

def sub(self):

return self.a-self.b

a=int(input("Enter first number: "))

b=int(input("Enter second number: "))

obj=cal(a,b)

choice=1

while choice!=0:

print("0. Exit")

print("1. Add")

print("2. Subtraction")

print("3. Multiplication")

print("4. Division")

choice=int(input("Enter choice: "))

if choice==1:

print("Result: ",obj.add())

elif choice==2:

print("Result: ",obj.sub())

elif choice==3:

print("Result: ",obj.mul())

elif choice==4:
print("Result: ",round(obj.div(),2))

elif choice==0:

print("Exiting!")

else:

print("Invalid choice!!")

print()

Lab 9c): Programming on class- Get All Possible Subsets from a Set of
Distinct Integers

class sub:

def f1(self, s1):

return self.f2([], sorted(s1))

def f2(self, curr, s1):

if s1:

return self.f2(curr, s1[1:]) + self.f2(curr + [s1[0]], s1[1:])

return [curr]

a=[]

n=int(input("Enter number of elements of list: "))

for i in range(0,n):

b=int(input("Enter element: "))

a.append(b)

print("Subsets: ")
print(sub().f1(a))

Lab 9d): Programming on class- Program to append, delete and display


elements of a list

class check():

def __init__(self):

self.n=[]

def add(self,a):

return self.n.append(a)

def remove(self,b):

self.n.remove(b)

def dis(self):

return (self.n)

obj=check()

choice=1

while choice!=0:

print("0. Exit")

print("1. Add")

print("2. Delete")

print("3. Display")

choice=int(input("Enter choice: "))


if choice==1:

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

obj.add(n)

print("List: ",obj.dis())

elif choice==2:

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

obj.remove(n)

print("List: ",obj.dis())

elif choice==3:

print("List: ",obj.dis())

elif choice==0:

print("Exiting!")

else:

print("Invalid choice!!")

print()

You might also like