Python utility that reads programming questions, generates C solutions via G4F, compiles/runs them locally, and exports a PDF report.
- AI-based C code generation using
g4f - Local compilation/execution via
gcc - Automatic input simulation for common
scanfformats - Parallel question processing
- PDF export with question, code, and runtime output
- Fallback handling for model/compile/runtime errors
- Python 3.6+
- GCC available on
PATH - Python packages:
fpdfg4f
- Clone this repository.
- Install dependencies:
pip install fpdf g4f- Ensure
gccis installed and callable from terminal.
- Create
questions.txtwith one question per line. - Run:
python3 main.py- Output PDF is created as
code_solutions.pdf.
Edit values in config.py:
QUESTIONS_FILE(default:questions.txt)FINAL_PDF(default:code_solutions.pdf)MAX_WORKERS(default:4)
main.py: Entry point and orchestrationconfig.py: Central configurationquestion_io.py: Read questions from filecodegen.py: G4F prompt/call and code cleanuprunner.py: GCC compile + execution simulationprocessor.py: Per-question processing pipelinepdf_builder.py: PDF layout and renderingtext_utils.py: Text cleanup and formatting helpers
Write a program to find the factorial of a number.
Create a program that checks if a number is prime.
- Generated prompts include student identification lines in the produced C code.
- Compilation timeout is 10 seconds; execution timeout is 5 seconds.
- Text is normalized for PDF Latin-1 compatibility.