python小练习-斐波纳契数列

 1 #!/usr/bin/env python
 2 #-*-coding:utf-8-*-
 3 __author__ = ""
 4 
 5 class Fibonacci(object):
 6     '''返回一个Fiboncci数列'''
 7     def __init__(self):
 8         self.fList = [0,1]#设置初始化列表
 9         self.main()
10 
11     def main(self):
12         listLen = raw_input("请输入数列的长度,3-50")
13         self.chackLen(listLen)
14         while len(self.fList) < int(listLen):
15             self.fList.append(self.fList[-1] + self.fList[-2])
16         print(u'得到的数列为:、n%s' %self.fList)
17 
18     def checkLen(self,lenth):#检查输入的数据是否正确
19         listLen = map(str,xrange(3,51))
20         if lenth in listLen:
21             print(u"输入的长度符合标准,继续运行")
22         else:
23             print(u'请输入3-50之间的数字试试')
24             exit()
25 
26 if __name__ =='__main_':
27     f = Fibonacci()

 

posted @ 2017-06-22 21:23  pylove  阅读(221)  评论(0)    收藏  举报