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.
Level: 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.
Level: easy
len(eb)
30

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.0.tar.gz (9.9 kB view hashes)

Uploaded Source

Built Distribution

exbook-0.0.0-py3-none-any.whl (10.3 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