0% found this document useful (0 votes)
2 views9 pages

Prep y Class

Uploaded by

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

Prep y Class

Uploaded by

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

from time import sleep

import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)

# Switch pin
GPIO.setup(25,GPIO.IN)

#LED pin

GPIO.setup(18,GPIO.OUT)

state = False
flag = 0
def toggleLED(pin,state):
if( state == False):
state = True
else:
state = False
GPIO.output(18,state)
return state

while True:
try:
if(GPIO.input(25) == True):
if(flag == 0):
state = toggleLED(18,state)
flag = 1
print 'if'
else:
print 'else'
flag = 0
sleep(.1)
except KeyboardInterrupt:
exit()
class Student:
studentCount = 0
def __init__(self,name,id):
print 'Constructor called'
self.name = name
self.id = id
Student.studentCount = Student.studentCount + 1
self.grades=

def __del__(self):
print 'Destructor called'

def getStudentCount(self):
return Student.studentCount

def addGrade(self,key,value):
self.grades[key] = value

def getGrade(self,key):
return self.grades[key]
def printGrades(self):
for key in self.grades:
print key + ": "+ self.grades[key]

a = Student('steve','92928')

a.addGrade('Math',90)
a.addGrade('Physics',85)
a.printGrades()

mathGrade = a.getGrade('Math')
print mathGrade

count = a.getStudentCount()

print count

del a
class Shape:
def __init__(self):
print 'Base class constructor'
self.color = 'Green'
self.lineWeight = 10.0
def draw(self):
print "Draw to be implemented"

def setColor(self,c):
self.color = c

def getColor(self):
return self.color

def setLineWeight(self,lwt):
self.lineWeight = lwt

def getLineWeight(self):
return self.lineWeight
class Circle(Shape):
def __init__(self,c,r):
print 'Child class constructor'
self.center = c
self.radius = r
self.color = 'Green'
self.lineWeight = 10.0
self.__label = 'Hidden circle label'

def setCenter(self,c):
self.center = c

def getCenter(self):
return self.center

def setRadius(self,r):
self.radius = r

def getRadius(self):
return self.radius

def draw(self):
print 'Draw circle overridden function'
class Point:

def __init__(self,x,y):
self.xCoordinate = x
self.yCoordinate = y

def setXCoordinate(self,x):
self.xCoordinate = x

def getXCoordinate(self):
return self.xCoordinate

def getYCoordinate(self):
return self.yCoordinate

def setYCoordinate(self,y):
self.yCoordinate = y
p = Point(2,4)

circ = Circle(p,7)

print circ.getColor()

circ.setColor('Red')

print circ.getColor()

print circ.getLineWeight()

print circ.getCenter().getXCoordinate()
print circ.getCenter().getYCoordinate()

circ.draw()

circ.__label

circ._Circle.__label

You might also like