首页 > 其他分享 >module2 review note

module2 review note

时间:2023-10-25 14:24:06浏览次数:28  
标签:stub testing return double review float module2 note Step

Module 2

The HtDF recipe consists of the following steps:

Step 1: Write the stub, including signature and purpose

Step 2: Define examples

Step 3: Write the template

Step 4: Code the function body

Step 5: Test and debug until correct

Step 1: Write the stub, including signature and purpose

@typecheck
def double(n: float) -> float: #signature
    """
    returns n doubled 
    """#purpose(属于stub)
    
    return 0      #stub[取决于output类型]

Stub作用:The stub serves as a scaffolding to make it possible to run the examples even before the function design is complete.

Step 2: Define examples

from cs103 import *

@typecheck
def double(n: float) -> float:
    """
    returns n doubled
    """
    
    return 0      #stub
________________________________下面的是examples
# Begin testing
start_testing()

expect(double(0), 2 * 0)
expect(double(-2.1), 2 * -2.1)
expect(double(10.11), 2 * 10.11)

# Show testing summary
summary()

Tips:
1.Examples 不光是 HtDD中的L10=12.3 这种的examples,在HtDF中就是这种在testing中的Examples
同时具有test 和eaxmples的作用

2.每个情况都要有一个 examples,不要疏漏

Step 3: Write the template

包含所有的自变量,ex:例子中的 n

from cs103 import *

@typecheck
def double(n: float) -> float:
    """
    returns n doubled
    """
    
    # return 0      #stub
________________________________下面的是template
    return ...(n)   #template
________________________________下面的是examples
# Begin testing
start_testing()

expect(double(0), 0)
expect(double(-2.1), 2 * -2.1)
expect(double(10.11), 2 * 10.11)

# Show testing summary
summary()

Step 4: Code the function body

@typecheck
def double(n: float) -> float:
    """
    returns n doubled
    """
    
    # return 0      #stub
    # return ...(n) #template
    return 2*n

给template前加“#”
同时给方程body(灵魂运算)

Step 5: Test and debug until correct

标签:stub,testing,return,double,review,float,module2,note,Step
From: https://www.cnblogs.com/zzhou75ubc/p/17787097.html

相关文章

  • JGoodies Usage Notes
    导包、设置导入包:<dependency><groupId>com.jgoodies</groupId><artifactId>forms</artifactId><version>1.2.1</version></dependency>idea里面布局切换一下:行列规范解释他是一个类似表格布局方式,你先设计好一个大的表格背景,然后将你想要的组件放置到指......
  • notepad++使用总结
    1.安装插件后,工具栏不显示图标问题安装完插件,工具栏所安装的插件图标没正常显示出来,鼠标放上去,会提示在设置里设置如下后,就可以正常显示......
  • NoteGPT是什么?到底怎么样?
    目前发现NoteGPT发展迅速,产品正在快速迭代,但具体是什么呢?总结来说,NoteGPT致力于建立一个结合AI的笔记产品,专注学习本身,提高学习效率。NoteGPT插件如何使用?(列举YouTube平台)安装插件:NoteGPT:SummarywithChatGPTandTakeNotes1. 自动获取YouTube视频的字幕这里我在使用的......
  • Burp Suite Extend APIs Notes
    Brup插件的开发,大体流程就是通过在自己创建的BurpExtender类上实现不同功能接口。所以,你想要开发出什么功能,就去找一下Burp上能提供什么接口,然后实现这个接口所需的方法即可。想要快速的开发的Burp插件、了解一下它的APIs是有必要的。下面我将梳理一下它提供出来的APIs。todoA......
  • 802.11ax协议notes
    不论上行MUMIMO(HETBPPDU)还是下行MUMIMO(HEMUPPDU),HE-LTF符号数都是由所有用户的总流数决定的。因此对于AP,上行无异于一个大的SUMIMO;下行,协议建议每个STA用上所有用户的信道信息来减少干扰。  HE-LTF模式:单流导频模式、多流导频模式(masked)、无导频模式  HETB格式除......
  • Julia notebook:矩阵乘法
    在本次notebook中,我们将:并行化一个简单的算法学习不同并行策略的performance使用Julia进行实现 问题描述假设所有矩阵,包括A,B和C都初始存储在masterprocess最终的结果会将在C中被覆盖步骤为了实现并行化,我们将遵循以下步骤:确定顺序算法中可以并行化的部分考虑......
  • Docker note
    1.1Docker服务相关命令启动dockers服务:systemctlstartdocker停止dockers服务:systemctlstopdocker重启dockers服务:systemctlrestartdocker查看dockers服务状态:systemctlstatusdocker设置开机启动docker服务:systemctlenabledocker1.2镜像相关命令1.2.1查......
  • PythonNotes_Basic1
    基本数据类型标准数据类型常见数据类型:Number(数字)String(字符串)bool(布尔类型)List(列表)Tuple(元组)Set(集合)Dictionary(字典)六个标准数据类型中:不可变数据(3个):Number(数字)、String(字符串)、Tuple(元组);可变数据(3个):List(列表)、Set(集合)、Dict......
  • PythonNote
    Python的编程模式分为两种:交互式,脚本式。(1)交互式:交互式编程,需要我们打开cmd窗口(命令提示符窗口),在窗口中键入python,回车,这样就进入了交互式编程。此时我们直接输入python语句,就可以得到运行的结果:(2)脚本式:是我们先把python语句写好,保存在后缀为.py的文件里,然后从外......
  • PythonNotes_Basic
    Python3基础目录1基本数据类型2数据类型转换3算术运算符4条件控制5条件控制6条件控制......