Python与Go斐波那契数列

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# 斐波那契数列 def fibonacci_sequence(num):
aa = 0
b = 1
li = list()
li.append(aa)
li.append(b)
for i in range(1, num):
aa, b = b, a + b
li.append(b)
return li if __name__ == '__main__':
a = fibonacci_sequence(10)
print(a)
package main

// 斐波那契数列
import "fmt" func FibonacciSequence(num int) (array []int) {
a := 0
b := 1
array = append(array, a)
array = append(array, b)
for i := 1; i < num; i ++ {
a, b = b, a + b
array = append(array, b)
}
return
} func main() {
a := FibonacciSequence(10)
fmt.Println(a)
}
上一篇:python练习题-打印斐波拉契数列前n项


下一篇:深度学习环境搭建(ubuntu16.04+Titan Xp安装显卡驱动+Cuda9.0+cudnn+其他软件)