我想写一个iPython笔记本,一套教科书中的问题答案,因为我喜欢这种格式。
但是我不想离开我的文本编辑器,我希望我最终写的是可执行的,因为答案有明确的价值所以我应该能够运行每个"回答"作为单元测试。
这样的文化python环境是否存在?
目前我有这个设置,这是原始的python,但我不能嵌入TeX或轻松生成格式良好的文档,这是ipynb非常擅长的。
test_question_1():
"""Question: What is the area of a triangle with a base of 3cm and a height of 5cm?
Answer: The general equation for area of a triangle is 0.5*base*height.
"""
base = 3
height = 5
target_answer = 7.5
assert library.area(base=base, height=height) == answer