Python编码练习

exbook的Python项目详细描述


练习exbook

exbook用于练习基本的Python编程。到目前为止,共有36个不同难度等级的问题。为了练习,建议您只使用基本的内置函数,如find()min()max()和{}。应避免导入包或更高级的函数或方法,如sort()argmin()、或{}。在

运行步骤exbook

步骤1:导入练习本

fromexbookimportbookaseblen(eb)
^{pr2}$

变量eb是一个包含36个问题的元组。在

第2步:打印问题

每个问题都可以由相应的索引检索,并且可以通过函数print()打印出来。在

print(eb[0])# Print the first question
Define a function with two strings to be the input arguments. The output is 
the summation of the numerical values of the input strings. For example, if 
the input strings are "3.5"and "2.7", then the output is 6.2, as a floating
point number.
Input1: strInput2: strOutput: float
Test 1:3.52.76.2

数据类型转换:简单

打印的问题信息包括:1)问题描述;2)样本输入和输出;3)问题的ID和难度级别。在

第3步:编写一个函数来解决问题

defdtc(string1,string2):returnfloat(string1)+float(string2)

第四步:检查问题的正确性

exbook包通过许多隐藏测试检查用户定义函数的正确性。这些测试可以通过check()方法运行。在

eb[0].check(dtc)
You passed 3 of the 3 tests. 
The solution is correct

如果您想知道测试有什么问题,可以指定参数cheat=True来显示这些隐藏测试的结果。在

eb[0].check(dtc,cheat=True)
^{tb2}$
You passed 3 of the 3 tests. 
The solution is correct

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
尝试连接到Red5服务器时出现java问题   java实现Runnable的类被认为是ExecutorServices的“Runnable任务”?   java struts2类中的多个@validation   java未能应用插件[class'org.gradle.api.plugins.scala.ScalaBasePlugin']:gradle v2。13   如何使用Java流仅收集长度最大的元素?   从spring引导应用程序连接到firestore的java引发空指针异常   java从SQLite插入和获取真实数据类型会为连续插入获取空值吗?   当存在未知数量的空格时,使用java替代正向查找   部署如何为当今的浏览器部署java小程序(小程序、嵌入、对象)?   @OneToMany和@ManyToOne@Formula之间的java双向关系返回null   java为什么在我的例子中,协议缓冲区的性能比JSON差?   如何部署混合C++/Java(JNI)应用程序?   java如何在程序中显示字符串的完整信息。反恐精英?   java在Hibernate中从持久性上下文中分离实体中的实体