Skip to content

Commit

Permalink
第一章作业
Browse files Browse the repository at this point in the history
  • Loading branch information
ruyiluo committed Sep 16, 2019
1 parent 5117001 commit 8b1018a
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Homework/ryl/lz_episode_01/fibonacci.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# 输出小于100的斐波那契数列
# 代码学习: 这里的b相当于是当前位置的数,而a每次都保存了前一次的值
print('小于100的斐波那契数列')
a = 0
b = 1
while b < 100:
print(b, end = " ")
a, b = b, a + b

11 changes: 11 additions & 0 deletions Homework/ryl/lz_episode_01/geometrically.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# 求整数的几何级数
# 等比数列求和公式: Sn = a(1-q**n)/(1-q)

print('几何级数')
a = int(input('a:'))
q = int(input('q:'))
n = int(input('n:'))

sum = a*(1-q**n)/(1-q)

print(sum)
23 changes: 23 additions & 0 deletions Homework/ryl/lz_episode_01/prime_number.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 暴力求解:质数只有1和本身是自己的因数,所以从2到本身减一去全部试探一遍
# 搜索到i**0.5就可以了

import time
import math
print('100万以内的质数')
start = time.time()
num = int(input('number:'))
ret = []
l = [2, 3, 5, 7, 9]
for i in range(2, num+1):
for a in l:
if i%a == 0:
continue

for j in range(2, int(i**0.5)):
if i%j == 0:
break
else:
ret.append(i)

print('Counts:', len(ret))
print('Time:', time.time()-start)
Binary file added Homework/ryl/lz_episode_01/作业截图.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8b1018a

Please sign in to comment.