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 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page