class Fib(object):
def __init__(self, num):
m = []
for x in range(num):
if x == 0:
m.append(0)
elif x == 1:
m.append(1)
else:
m.append(m[-2]+m[-1])
self.o = m
def __init__(self, num):
m = []
for x in range(num):
if x == 0:
m.append(0)
elif x == 1:
m.append(1)
else:
m.append(m[-2]+m[-1])
self.o = m
2015-09-07
(2):
def count():
l = []
for x in range(1,4):
def f():
return x*x
l.append(f())
return l
print count()
def count():
l = []
for x in range(1,4):
def f():
return x*x
l.append(f())
return l
print count()
2015-09-06
你们运行下这两段代码
(1):
def count():
l = []
for x in range(1,4):
def f():
return x*x
l.append(f)
return l
print count()
print count()[0]()
print count()[1]()
print count()[2]()
(1):
def count():
l = []
for x in range(1,4):
def f():
return x*x
l.append(f)
return l
print count()
print count()[0]()
print count()[1]()
print count()[2]()
2015-09-06
难度跨越好大,不看答案做不出来,看了答案也不过似懂非懂,time模块挺突兀的,不提前知道都不知怎么冒出来的,__name__这个东西虽然猜也能猜到是啥,但是没有讲过终究是不能很好的理解。这节能再细化些就好了。。。
2015-09-06
# -*- coding:utf8 -*-
# 第一行记得写以上代码
class Person(object):
# ...
def get_grade(self):
if self.__score >= 90:
return u'A-优秀'
elif self.__score >= 60:
return u'B-及格'
else:
return u'C-不及格'
# 第一行记得写以上代码
class Person(object):
# ...
def get_grade(self):
if self.__score >= 90:
return u'A-优秀'
elif self.__score >= 60:
return u'B-及格'
else:
return u'C-不及格'
2015-09-06
class Person(object):
def __init__(self,name,gender,birth,**kw):
self.name = name
self.gender = gender
self.birth = birth
for k,v in kw.items():
setattr(self,k,v)
def __init__(self,name,gender,birth,**kw):
self.name = name
self.gender = gender
self.birth = birth
for k,v in kw.items():
setattr(self,k,v)
2015-09-06
def cmp_ignore_case(s1, s2):
if ord(s1[0].lower()) <= ord(s2[0].lower()):
return -1
else:
return 1
print sorted(['bob','about','Zoo','Credit'],cmp_ignore_case)
if ord(s1[0].lower()) <= ord(s2[0].lower()):
return -1
else:
return 1
print sorted(['bob','about','Zoo','Credit'],cmp_ignore_case)
2015-09-05
import math
def is_sqr(x):
if math.sqrt(x)%1 == 0:
return True
else:
return False
print filter(is_sqr, range(1, 101))
def is_sqr(x):
if math.sqrt(x)%1 == 0:
return True
else:
return False
print filter(is_sqr, range(1, 101))
2015-09-05
def format_name(s):
return s.lower().title()
print map(format_name, ['adam', 'LISA', 'barT'])
return s.lower().title()
print map(format_name, ['adam', 'LISA', 'barT'])
2015-09-04
import json
class Students(object):
def __init__(self,lists):
self.lists=lists
def read(self):
return self.lists.lower()
L=r'["Time","Bob","Alice"]'
s = Students(L)
print json.load(s)
明明输出是正确的,但是就是不给我通过,求解释啊
class Students(object):
def __init__(self,lists):
self.lists=lists
def read(self):
return self.lists.lower()
L=r'["Time","Bob","Alice"]'
s = Students(L)
print json.load(s)
明明输出是正确的,但是就是不给我通过,求解释啊
2015-09-04