The package exbook
is used for practicing basic Python programming. So far there are totally 36 questions with different difficulty levels. For the purpose of practicing, you are recommended to only use basic built-in functions like find()
, min()
, max()
and sum()
. Imported packages or more advanced functions or methods, such as sort()
, argmin()
, or split()
should be avoided.
We also provide the online version of exbook
and you can access it at: https://nus-biz-dao.herokuapp.com/
from exbook import book as eb
len(eb)
36
The variable eb
is a tuple containing 36 questions.
Each question can be retrieved by the corresponding indices, and can be printed by the function 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 |
Data Type Conversion: Easy
The printed question information includes: 1) the description of the question; 2) sample inputs and outputs; and 3) the ID and difficulty level of the question.
def dtc(string1, string2):
return float(string1) + float(string2)
The exbook
package checks the correctness of the user-defined functions by a number of hidden tests. These tests can be run by the method check()
.
eb[0].check(dtc)
You passed 3 of the 3 tests.
The solution is correct
In case you want to know what is wrong with the tests, you may specify the argument cheat=True
to show the results of these hidden tests.
eb[0].check(dtc, cheat=True)
Input 1: str | Input 2: str | Your output | Correct output: float | Correct | |
---|---|---|---|---|---|
Test 1: | 3.5 | 2.7 | 6.2 | 6.2 | True |
Test 2: | 1.2 | 5 | 6.2 | 6.2 | True |
Test 3: | 2 | 4 | 6.0 | 6 | True |
You passed 3 of the 3 tests.
The solution is correct