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: str | Input2: str | Output: float | |
---|---|---|---|
Test 1: | 3.5 | 2.7 | 6.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
- 项目
标签: