Table of Contents
The following external dependencies need to be pre-installed in order to host your own CTPy game server.
- Python 3.6 +
- flask
pip install flask
- Clone the repo and cd into the folder
git clone https://github.com/solamarpreet/CTPy.git && cd CTPy
- Start the game server
python3 server/ctpy-server.py
- Open a new terminal and start the Python shell
python3
- Import the ctpy.py file into the Python shell
from ctpy import *
- Fetch Question 1 and start playing :)
game.question(1)
In order to play you need to make use of the 'game' object that has already been initialized for you. This 'game' object has 3 methods available which you need to use:
This method pulls the question text from the server and displays it on the console. It accepts one parameter i.e Question Number
game.question(1)This method fetches the data associated with the Question. It accepts one parameter i.e Question Number
game.data(1)This method submits your answer to the server and returns a string telling you if your answer was correct or incorrect. It accepts 2 parameters i.e The Question Number you are submitting the answer for and the answer itself.
game.answer(1, 'This is the answer')or
game.answer(1, x)
# where x is a variable containing the answeror
game.answer(1, myfunc())
# where myfunc is a function that calculates the answerIf you get an error stating '[Errno 111] Connection refused' then it is possible that Flask started the HTTP server on a non default port.
In that case check the terminal output you get after you run the Step 2 of the Installation process. Take a note of the port number and make the change in the last line of ctpy.py file as follows
# game = Game('http://127.0.0.1:5000')
game = Game('http://127.0.0.1:<your-port-number-here>')
If that does not help address your issue check the open issues for a list known issues and open a new issue.
- Dynamic question data to ensure solutions are obtained in a programatic fashion
- Segregated beginner, intermediate and advanced challenge paths
Please contribute additional quality questions/challenges so that Python beginners can continue to benefit from this project.
If you have a question that you wish to add, simply open an issue with the tag "question". You can also fork the repo, add your code and create a pull request.
Distributed under the GPLv3 License. See LICENSE for more information.
Amarpreet Singh - [email protected]
Blog & Portfolio : https://solamarpreet.github.io