Skip to main content

Exercises for Python coding

Project description

Python Exercise Package

An example of using exbook

The package exbook contains a number of coding exercise questions for you to practice. It can check your solution via a series of tests. You may follow the following steps to use exbook.

  1. Install the package via running pip install exbook.

  2. Import the package by the following code.

from exbook import book as eb  # Import the exercise book from the exbook package
  1. After importing the exercise book, we can use eb[i] to access each question in the exercise book. For example, the following code print the description of the first question eb[0].
eb[0]
Example(s):
<style scoped> .dataframe tbody tr th:only-of-type { vertical-align: middle; }
.dataframe tbody tr th {
    vertical-align: top;
}

.dataframe thead th {
    text-align: right;
}
</style>
Input1 Input2 Output
0 3.5 2.7 6.2
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 inputs are "3.5" and "2.7", then the output is 6.2.
?[1mLevel:?[0;0m easy
  1. You need to write a function according to the question description.
"""Solution to the question"""
def sum_str(a, b):              # The function as the solution
    return float(a) + float(b)  # Return the summation of numerical values
  1. The last step is to run the method check of the question eb[0], then exbook would use a number of tests to check if your function is the correct solution to the exercise question.
# Check if the function "sum_str" is a correct solution 

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

If you cannot figure out the correct answer, you may set the argument cheat of the function check to be True, to display the information on why your solution is wrong.

# Check the function "sum_str" and display the correct solutions

eb[0].check(sum_str, cheat=True)   
<style scoped> .dataframe tbody tr th:only-of-type { vertical-align: middle; }
.dataframe tbody tr th {
    vertical-align: top;
}

.dataframe thead th {
    text-align: right;
}
</style>
Input1 Input2 Your output Correct output Correct
0 3.5 2.7 6.2 6.2 True
1 1.2 5 6.2 6.2 True
2 2 4 6.0 6 True
You passed 3 of the 3 tests. 
The solution is correct

There are totally 30 questions with different levels of difficulties in the module. You may now work on the other questions.

len(eb)

eb[1]
Example(s):
<style scoped> .dataframe tbody tr th:only-of-type { vertical-align: middle; }
.dataframe tbody tr th {
    vertical-align: top;
}

.dataframe thead th {
    text-align: right;
}
</style>
Input1 Output
0 151 True
1 -5 True
Write a function to determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward. For example, 121 is a palindrome so the output is True, 10 is not a palindrome so the output is False.
?[1mLevel:?[0;0m easy
len(eb)
30

Project details


Release history Release notifications

This version

0.0.0

Download files

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

Files for exbook, version 0.0.0
Filename, size File type Python version Upload date Hashes
Filename, size exbook-0.0.0-py3-none-any.whl (10.3 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size exbook-0.0.0.tar.gz (9.9 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page