def __str__(self):
n = self.gcd(self.p,self.q)
return '%s/%s' % (self.p/n,self.q/n)
def gcd(self,n1,n2):
if n1%n2 == 0:
return n2
return self.gcd(n2,n1%n2)
n = self.gcd(self.p,self.q)
return '%s/%s' % (self.p/n,self.q/n)
def gcd(self,n1,n2):
if n1%n2 == 0:
return n2
return self.gcd(n2,n1%n2)
2018-02-27
def __str__(self):
return str(self.fab(self.num))
def __len__(self):
return len(self.fab(self.num))
return str(self.fab(self.num))
def __len__(self):
return len(self.fab(self.num))
2018-02-27
def __init__(self, num):
self.num = num
def fab(self,count):
L = []
n,a,b = 0,0,1
while n < count-1:
if n== 0:
L.append(a)
L.append(b)
a,b = b,a+b
n += 1
return L
self.num = num
def fab(self,count):
L = []
n,a,b = 0,0,1
while n < count-1:
if n== 0:
L.append(a)
L.append(b)
a,b = b,a+b
n += 1
return L
2018-02-27
def cmp_ignore_case(s1, s2):
return 1 if s1.lower() > s2.lower() else -1 if s1.lower() < s2.lower() else 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
return 1 if s1.lower() > s2.lower() else -1 if s1.lower() < s2.lower() else 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
2018-02-27
def __str__(self):
return '(Student: %s, %s, %s)' % (self.name,self.gender,self.score)
return '(Student: %s, %s, %s)' % (self.name,self.gender,self.score)
2018-02-27
def __init__(self, name, gender, **kw):
self.name = name
self.gender = gender
for k,v in kw.items():
setattr(self,k,v)
self.name = name
self.gender = gender
for k,v in kw.items():
setattr(self,k,v)
2018-02-27
def __init__(self, name, gender, **kw):
self.name = name
self.gender = gender
for k,v in kw.iteritems():
setattr(Person,k,v)
self.name = name
self.gender = gender
for k,v in kw.iteritems():
setattr(Person,k,v)
2018-02-27
def __init__(self, name, gender, **kw):
self.name = name
self.gender = gender
if 'age' in kw:
self.age = kw['age']
if 'course' in kw:
self.course = kw['course']
self.name = name
self.gender = gender
if 'age' in kw:
self.age = kw['age']
if 'course' in kw:
self.course = kw['course']
2018-02-27
class BStudent(Student,BasketballMixin):
pass
class FTeacher(Teacher,FootballMixin):
pass
pass
class FTeacher(Teacher,FootballMixin):
pass
2018-02-27
class BStudent(BasketballMixin):
pass
class FTeacher(FootballMixin):
pass
pass
class FTeacher(FootballMixin):
pass
2018-02-27
import json
class Students(object):
def read(self):
return r'["Tim", "Bob", "Alice"]'
s = Students()
print json.load(s)
class Students(object):
def read(self):
return r'["Tim", "Bob", "Alice"]'
s = Students()
print json.load(s)
2018-02-27
class Teacher(Person):
def __init__(self, name, gender, course):
super(Teacher,self).__init__(name,gender)
self.course = course
def __init__(self, name, gender, course):
super(Teacher,self).__init__(name,gender)
self.course = course
2018-02-27
class Person(object):
__count = 0
@classmethod
def how_many(s):
return s.__count
def __init__(self,name):
self.name = name
Person.__count += 1
print Person.how_many()
p1 = Person('Bob')
print Person.how_many()
__count = 0
@classmethod
def how_many(s):
return s.__count
def __init__(self,name):
self.name = name
Person.__count += 1
print Person.how_many()
p1 = Person('Bob')
print Person.how_many()
2018-02-27
def __init__(self, name, score):
self.name = name
self.__score = score
def get_grade(self):
if self.__score > 80:
print self.name,'-','优秀'
elif self.__score > 60:
print self.name,'-','及格'
else:
print self.name,'-','不及格'
self.name = name
self.__score = score
def get_grade(self):
if self.__score > 80:
print self.name,'-','优秀'
elif self.__score > 60:
print self.name,'-','及格'
else:
print self.name,'-','不及格'
2018-02-27