Skip to main content

Exercises for Python coding

Project description

Practice with exbook Package

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.

Steps of running exbook

Step 1: import the exercise book

from exbook import book as eb

len(eb)
36

The variable eb is a tuple containing 36 questions.

Step 2: print 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.

Step 3: write a function to solve the question

def dtc(string1, string2):

    return float(string1) + float(string2)

Step 4: check the correctness of the question

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

exbook-0.0.3.tar.gz (11.4 kB view hashes)

Uploaded source

Built Distribution

exbook-0.0.3-py3-none-any.whl (10.9 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page