栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

CS 61A 2020 fall Disc 01: Environment Diagrams, Control

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

CS 61A 2020 fall Disc 01: Environment Diagrams, Control

1.3 Write a function that returns True if a positive integer n is a prime number and False otherwise.

A prime number n is a number that is not divisible by any numbers other than 1 and n itself. For example, 13 is prime, since it is only divisible by 1 and 13, but 14 is not, since it is divisible by 1, 2, 7, and 14.

Hint: use the % operator: x % y returns the remainder of x when divided by y.

def is_prime(n):
 is_prime(10)
False
 is_prime(7)
 if n 1:
 return False
 while k n:
 if n % k 0:
 return False
 return True

2.1 Use these rules to draw a simple diagram for the assignment statements below.

x 10 % 4
y x
x ** 2

 

2.2 Use these rules and the rules for assignment statements to draw a diagram for the
code below. 

def double(x):
 return x * 2
def triple(x):
 return x * 3
hat double
double triple

2.3 Let’s put it all together! Draw an environment diagram for the following code.

def double(x):
 return x * 2
hmmm double
wow double(3)
hmmm(wow)

 

2.4 Tutorial: Draw the environment diagram that results from executing the code
below.

def f(x):
 return x
def g(x, y):
 if x(y):
 return not y
 return y
x g(f, x)
f g(f, 0)

 

 

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/268068.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号