computer science 101-unit2 some exercise
2018-03-04 21:36
190 查看
1.中位数函数
def bigger(a,b):
if a > b:
return a
else:
return b
def biggest(a,b,c):
return bigger(a,bigger(b,c))
def median(a,b,c):
big = biggest(a,b,c)
if big == a:
return bigger(b,c)
if big == b:
return bigger(a,c)
else:
return bigger(a,b)
2. find_last 函数
def find_last(s,t):
last_pos = -1
while True:
pos = s.find(t, last_pos + 1)
if pos == -1:
return last_pos
last_pos = pos
3. 乘法表
def print_multiplication_table(n):
i = 1
while i <= n:
j = 1
while j <= n:
print str(i) + ' * ' + str(j) + ' = ' + str(i * j)
j = j + 1
i = i + 1
输出结果:
#print_multiplication_table(2)
#>>> 1 * 1 = 1
#>>> 1 * 2 = 2
#>>> 2 * 1 = 2
#>>> 2 * 2 = 4
def bigger(a,b):
if a > b:
return a
else:
return b
def biggest(a,b,c):
return bigger(a,bigger(b,c))
def median(a,b,c):
big = biggest(a,b,c)
if big == a:
return bigger(b,c)
if big == b:
return bigger(a,c)
else:
return bigger(a,b)
2. find_last 函数
def find_last(s,t):
last_pos = -1
while True:
pos = s.find(t, last_pos + 1)
if pos == -1:
return last_pos
last_pos = pos
3. 乘法表
def print_multiplication_table(n):
i = 1
while i <= n:
j = 1
while j <= n:
print str(i) + ' * ' + str(j) + ' = ' + str(i * j)
j = j + 1
i = i + 1
输出结果:
#print_multiplication_table(2)
#>>> 1 * 1 = 1
#>>> 1 * 2 = 2
#>>> 2 * 1 = 2
#>>> 2 * 2 = 4
相关文章推荐
- computer science 101- unit2-exercise2
- computer science 101-unit1-python2字符串小结
- computer science 101 unit3--list
- Computer Science 学习第四章--CPU 指令集及指令处理
- 40 Key Computer Science Concepts Explained In Layman’s Terms
- Computer 101
- 麻省理工学院 电机工程与资讯科学(Electrical Engineering and Computer Science) 在线课程列表
- Mathematics for Computer Science
- 计算机学术期刊排名:Computer Science Journal Rankings
- Computer Science Journal Rankings 转
- What is a good computer science book?
- GRE Subject Test Computer Science (GRE Sub CS) 考试经验
- Computer Science
- 6.00 Introduction to Computer Science and Programming Lec 9: Lecture 9: Memory and Search Methods
- Best Paper Awards in Computer Science 链接
- 【MIT 公开课】Computer Science and Programing Lession 11
- 【收藏】Advice for Computer Science College Students
- 译文-Teach Yourself Computer Science-自学计算机科学
- Extinguished resources of computer science
- 听讲座笔记:图灵奖在清华——与姚期智院士对话 China Computer Science 2020