1. เวอร์ชั่นที่ตรงไปตรงมา
สคริปต์ด้านล่างนี้จะผลิตที่ได้รับมอบหมายที่สุ่ม+ , - , ×และ÷ คุณสามารถ (และควร) กำหนดจำนวนสูงสุดที่สคริปต์อาจใช้รวมถึงช่วงเวลาระหว่างการกำหนด
ที่ได้รับมอบหมาย
การบ้านจะถูกแสดงในหน้าต่างรายการ Zenity:

ถ้าคำตอบไม่ถูกต้อง:

หากคำตอบนั้นถูกต้อง:

สคริปต์
#!/usr/bin/env python3
from random import randint
import sys
import subprocess
import time
# maximum number & interval
max_n = int(sys.argv[1]); pause = int(sys.argv[2])
def fix_float(n):
    """
    if the assignment is a division, the script divides the random number by a
    number (integer) it can be divided by. it looks up those numbers, and picks
    one of them (at random). if the number is a prime number the assignment is
    changed into another type
    """
    try:
        divs = [i for i in range(2, n) if n%i == 0]
        pick = randint(1, len(divs))
        div_by = divs[pick-1]
        return [str(n)+" : "+str(div_by), int(n/div_by)]
    except (ValueError, IndexError):
        pass
def get_assignment():
    """
    get a random number within the user defined range, make the assignment and
    the textual presentation
    """
    n1 = randint(2, max_n); n2 = randint(2, max_n)
    assignments = [
        [str(n1)+" + "+str(n2), n1+n2],
        [str(n1)+" - "+str(n2), n1-n2],
        [str(n1)+" x "+str(n2), n1*n2],
        fix_float(n1),
        ]
    # pick an assignment (type) at random
    assignment = assignments[randint(0, 3)]
    # if the random number is a prime number and the assignment a division...
    assignment = assignment if assignment != None else assignments[1]
    # run the interface job
    try:
        answer = int(subprocess.check_output(["/bin/bash", "-c",
            'zenity --entry --title="Think hard:" --text='+'"'+assignment[0]+'"'
            ]).decode("utf-8"))
        if answer == assignment[1]:
            subprocess.Popen(["notify-send", "Coolcool"])
        else:
            subprocess.Popen([
                "notify-send", "Oooops, "+assignment[0]+\
                " = "+str(assignment[1])])
    except (subprocess.CalledProcessError, ValueError):
        pass
while True:
    time.sleep(pause)
    get_assignment()
วิธีใช้
- คัดลอกสคริปต์ลงในไฟล์ว่างแล้วบันทึกเป็น 
mindpractice.py 
รันด้วยจำนวนสูงสุดที่อนุญาตและเวลาช่วงเวลา (เป็นวินาที) ระหว่างการกำหนดเป็นอาร์กิวเมนต์:
python3 /path/to/mindpractice.py <max_number> <interval>
เช่น 
python3 /path/to/mindpractice.py 1000 300
เพื่อทำการคำนวณได้มากถึงตัวเลข1000ด้วยเวลาพัก 5 นาทีระหว่างที่ได้รับมอบหมาย
 
หากใช้งานได้ดีคุณสามารถเพิ่มลงในแอปพลิเคชั่นเริ่มต้นตามปกติหรือเปิดใช้งานตัวเปิดใช้งานเพื่อสลับซึ่งฉันอาจเพิ่มในภายหลัง :)
 
บันทึก
- การหารอาจต้องการคำอธิบาย คุณอาจไม่ต้องการคำนวณแบบลอย ดังนั้นหากการมอบหมายเป็นส่วนสคริปต์จะค้นหาตัวเลขที่สามารถหารด้วยและเลือกหนึ่งตัว (โดยการสุ่ม) หากหมายเลข (หลัก) กลายเป็นหมายเลขเฉพาะการมอบหมายจะถูกเปลี่ยนเป็นประเภทอื่น
 
2. ตัวเลือกเพิ่มเติม
เมื่อคุณเริ่มคำนวณคุณจะพบว่าการหารด้วยตัวเลข (สมมติว่า) 100 นั้นง่ายกว่าการคูณตัวเลขมากถึง 100
ด้วยสคริปต์ด้านล่างคุณสามารถ (และควร) ตั้งค่าจำนวนสูงสุดต่อประเภทการออกกำลังกาย (ดูคำแนะนำด้านล่างสคริปต์)
สคริปต์
#!/usr/bin/env python3
from random import randint
import sys
import subprocess
import time
levels = sys.argv[1:]
pause = [int(arg.replace("p:", "")) for arg in levels if "p:" in arg][0]
def fix_float(n):
    """
    if the assignment is a division, the script divides the random number by a
    number (integer) it can be divided by. it looks up those numbers, and picks
    one of them (at random). if the number is a prime number the assignment is
    changed into another type
    """
    try:
        divs = [i for i in range(2, n) if n%i == 0]
        pick = randint(1, len(divs))
        div_by = divs[pick-1]
        return [str(n)+" : "+str(div_by), int(n/div_by)]
    except (ValueError, IndexError):
        pass
def get_assignment():
    """
    get a random number within the user defined range, make the assignment and
    the textual presentation
    """
    # pick an assignment (type) at random
    track = randint(0, 3)
    arg = ["a:", "s:", "m:", "d:"][track]
    max_n = [int(item.replace(arg, "")) for item in levels if arg in item][0]
    n1 = randint(2, max_n); n2 = randint(2, max_n)
    assignments = [
        [str(n1)+" + "+str(n2), n1+n2],
        [str(n1)+" - "+str(n2), n1-n2],
        [str(n1)+" x "+str(n2), n1*n2],
        fix_float(n1),
        ]
    assignment = assignments[track]     
    # if the random number is a prime number and the assignment a division...
    assignment = assignment if assignment != None else assignments[1]
    # run the interface job
    try:
        answer = int(subprocess.check_output(["/bin/bash", "-c",
            'zenity --entry --title="Think hard:" --text='+'"'+assignment[0]+'"'
            ]).decode("utf-8"))
        if answer == assignment[1]:
            subprocess.Popen(["notify-send", "Coolcool"])
        else:
            subprocess.Popen([
                "notify-send", "Oooops, "+assignment[0]+\
                " = "+str(assignment[1])])
    except (subprocess.CalledProcessError, ValueError):
        pass
while True:
    time.sleep(pause)
    get_assignment()
วิธีใช้
ตั้งค่าสคริปต์ให้เหมือนกับสคริปต์แรก แต่รันด้วยอาร์กิวเมนต์ (ในลำดับใด ๆ สคริปต์จะเชื่อมโยงอาร์กิวเมนต์ที่ถูกต้องกับรายการที่ถูกต้อง):
p: หยุดชั่วคราว (หยุดพักระหว่างการมอบหมายหน่วยเป็นวินาที)) 
s: ลบ (จำนวนสูงสุดที่จะคำนวณด้วย) 
a: เพิ่ม (จำนวนสูงสุด) 
m: ทวีคูณ (จำนวนสูงสุด) 
d: หาร (จำนวนสูงสุด) 
ตัวอย่างเช่น:
python3 '/home/jacob/Desktop/num.py' a:10 d:100 s:10 m:10 p:300
เพื่อแสดงการออกกำลังกายทุกห้านาทีตัวเลขสูงถึง 10 ยกเว้นการหารถึงรูปที่ 100
 
3. ไปกันเถอะ
ความสามารถในการดูสถิติบางอย่าง
รุ่นด้านล่างแสดงสถิติหลังการออกกำลังกาย 10 ครั้ง:

นอกจากนี้ (อาจมีประโยชน์เมื่อใช้กับเด็ก ๆ ) คุณสามารถดูว่าเกิดข้อผิดพลาดอะไรในการฝึกตอบที่ไม่ถูกต้อง 100 ครั้งล่าสุด ในไฟล์ที่ซ่อนอยู่จะมีการเขียนทั้งการมอบหมายและคำตอบ (ไม่ถูกต้อง) ไว้:

ไฟล์บันทึกนี้ตั้งอยู่:
~/.calculog
สคริปต์
#!/usr/bin/env python3
from random import randint
import sys
import subprocess
import time
import os
log = os.environ["HOME"]+"/.calculog"
levels = sys.argv[1:]
pause = [int(arg.replace("p:", "")) for arg in levels if "p:" in arg][0]
def fix_float(n):
    """
    if the assignment is a division, the script divides the random number by a
    number (integer) it can be divided by. it looks up those numbers, and picks
    one of them (at random). if the number is a prime number the assignment is
    changed into another type
    """
    try:
        divs = [i for i in range(2, n) if n%i == 0]
        pick = randint(1, len(divs))
        div_by = divs[pick-1]
        return [str(n)+" : "+str(div_by), int(n/div_by)]
    except (ValueError, IndexError):
        pass
def get_assignment():
    """
    get a random number within the user defined range, make the assignment and
    the textual presentation
    """
    # pick an assignment (type) at random
    track = randint(0, 3)
    arg = ["a:", "s:", "m:", "d:"][track]
    max_n = [int(item.replace(arg, "")) for item in levels if arg in item][0]
    n1 = randint(2, max_n); n2 = randint(2, max_n)
    assignments = [
        [str(n1)+" + "+str(n2), n1+n2],
        [str(n1)+" - "+str(n2), n1-n2],
        [str(n1)+" x "+str(n2), n1*n2],
        fix_float(n1),
        ]
    assignment = assignments[track]     
    # if the random number is a prime number and the assignment a division...
    assignment = assignment if assignment != None else assignments[1]
    # run the interface job
    try:
        answer = int(subprocess.check_output(["/bin/bash", "-c",
            'zenity --entry --title="Think hard:" --text='+'"'+assignment[0]+'"'
            ]).decode("utf-8"))
        if answer == assignment[1]:
            subprocess.Popen(["notify-send", "Coolcool"])
            return "ok"
        else:
            subprocess.Popen([
                "notify-send", "Oooops, "+assignment[0]+\
                " = "+str(assignment[1])])
            open(log, "+a").write(assignment[0]+"\t\t"+str(answer)+"\n")
            try:
                history = open(log).read().splitlines()
                open(log, "wt").write(("\n").join(history[-100:])+"\n")     
            except FileNotFoundError:
                pass 
            return "mistake"
    except (subprocess.CalledProcessError, ValueError):
        return None
results = []
while True:
    time.sleep(pause)
    results.append(get_assignment())
    if len(results) >= 10:
        score = results.count("ok")
        subprocess.call([
            "zenity", "--info",
            '--title=Latest scores',
            '--text='+str(score)+' out of 10',
            '--width=160',
            ])
        results = []
วิธีใช้
การใช้งานค่อนข้างคล้ายกับตัวเลือก 2 แต่คุณจะมี logfile และคะแนนหลังจากการมอบหมาย 10 ครั้ง
4. รุ่นที่ดีที่สุด
รุ่นด้านล่างเป็นเหมือนตัวเลือก 3 (รวมถึงไฟล์บันทึกและรายงาน) แต่มีคุณสมบัติเพิ่มเติมบางอย่าง:
เพิ่มการคำนวณสแควร์รูท

 
เพิ่มโดยใช้ช่วงของตัวเลขแทนที่จะเพียงตั้งค่าสูงสุด
 
- เพิ่มตัวเลือกในการทำงานเฉพาะที่เฉพาะเจาะจงประเภทการคำนวณ (เช่นเพียงแบ่งและคูณ)
 
จำข้อโต้แย้งที่มันถูกเรียกใช้ในครั้งสุดท้ายเมื่อรันโดยไม่มีข้อโต้แย้ง (เฉพาะครั้งแรกต้องตั้งค่าอาร์กิวเมนต์) หากไม่มีการตั้งค่าอาร์กิวเมนต์ในการเรียกใช้ครั้งแรกสคริปต์จะส่งข้อความ:

 
สคริปต์
#!/usr/bin/env python3
from random import randint
import sys
import subprocess
import time
import os
"""
Use this script to practice head count. Some explanation might be needed:
The script can be used for the following types of calculating:
Type          argument example      explanation
-------------------------------------------------------------------------------
add           a:30-100              to add in numbers from 30-100
subtract      s:10-100              to subtract in numbers from 10-100
multiply      m:10-20               to multiply in numbers from 10-20
divide        d:200-400             to divide in numbers from 200-400
square root   r:1-1000              to find square root in numbers from 1-1000
N.B.
-------------------------------------------------------------------------------
- The argument p: (pause in seconds; break between the assignments) *must* be
  set, for example: p:300 to launch an assignment every 5 minutes
- A calculation type will only run *if* the argument is set for the
  corresponding type. An example: python3 /path/to/script p:60 s:30-60
  will run a subtract- assignment every minute.
Miscellaneous information:
-------------------------------------------------------------------------------
- On first run, arguments *must* be set. After first run, when no arguments
  are used the last set arguments will run, until the script is run with a new
  set of arguments.
- A log file of the last 100 incorrectly answered questions is kept in
  ~/.calculog
- After 10 assignments, the score of the last 10 pops up.
"""
log = os.environ["HOME"]+"/.calculog"
prefs = os.environ["HOME"]+"/.calcuprefs"
levels = sys.argv[1:]
if levels:
    open(prefs, "wt").write(str(levels))
else:
    try:
        levels = eval(open(prefs).read())
    except FileNotFoundError:
        subprocess.call([
            "zenity", "--info",
            '--title=Missing arguments',
            '--text=On first run, the script needs to be run with arguments\n'
            ])
def fix_float(n):
    """
    if the assignment is a division, the script divides the random number by a
    number (integer) it can be divided by. it looks up those numbers, and picks
    one of them (at random). if the number is a prime number the assignment is
    changed into another type
    """
    try:
        divs = [i for i in range(2, n) if n%i == 0]
        pick = randint(1, len(divs))
        div_by = divs[pick-1]
        return [str(n)+" : "+str(div_by), int(n/div_by)]
    except (ValueError, IndexError):
        pass
def fix_sqr(f1, f2):
    """
    If the assignment is calculating a square root, this function finds the sets
    of numbers (integers) that make a couple, within the given range.
    """
    q = f1; r = q**(.5); sets = []
    while q < f2:
        r = q**(.5)
        if r == int(r):
            sets.append([int(r), int(q)])
        q = q+1
    if sets:
        pick = sets[randint(0, len(sets)-1)]
        return ["√"+str(pick[1]), pick[0]]
def get_assignment():
    """
    get a random number within the user defined range, make the assignment and
    the textual presentation
    """ 
    args = ["a:", "s:", "m:", "d:", "r:"]
    indc = []
    for i, item in enumerate(args):
        if item in str(levels):
            indc.append(i)
    index = indc[randint(0, len(indc)-1)]
    name = args[index]
    minmax = [
        [int(n) for n in item.replace(name, "").split("-")] \
        for item in levels if name in item][0]
    assignment = None
    # if the random number is a prime number *and* the assignment a division 
    # or a square root...
    while assignment == None:
        n1 = randint(minmax[0], minmax[1]); n2 = randint(minmax[0], minmax[1])
        assignment = [
            [str(n1)+" + "+str(n2), n1+n2],
            [str(n1)+" - "+str(n2), n1-n2],
            [str(n1)+" x "+str(n2), n1*n2],
            fix_float(n1),
            fix_sqr(minmax[0], minmax[1]),
            ][index]
    # run the interface job
    try:
        answer = int(subprocess.check_output(["/bin/bash", "-c",
            'zenity --entry --title="Think hard:" --text='+'"'+assignment[0]+'"'
            ]).decode("utf-8"))
        if answer == assignment[1]:
            subprocess.Popen(["notify-send", "Coolcool"])
            return "ok"
        else:
            subprocess.Popen([
                "notify-send", "Oooops, "+assignment[0]+\
                " = "+str(assignment[1])])
            open(log, "+a").write(assignment[0]+"\t\t"+str(answer)+"\n")
            try:
                history = open(log).read().splitlines()
                open(log, "wt").write(("\n").join(history[-100:])+"\n")     
            except FileNotFoundError:
                pass 
            return "mistake"
    except (subprocess.CalledProcessError, ValueError):
        return None
if levels:
    pause = [int(arg.replace("p:", "")) for arg in levels if "p:" in arg][0]
    [levels.remove(item) for item in levels if "p:" in item]
    results = []
    while True:
        time.sleep(pause)
        results.append(get_assignment())
        if len(results) >= 10:
            score = results.count("ok")
            subprocess.call([
                "zenity", "--info",
                '--title=Latest scores',
                '--text='+str(score)+' out of 10',
                '--width=160',
                ])
            results = []
วิธีใช้
คัดลอกสคริปต์ลงในไฟล์ที่ว่างเปล่าบันทึกไว้ (อีกครั้ง) mindpractice.pyในฐานะ เรียกใช้ด้วยตัวเลือกต่อไปนี้ (เป็นตัวอย่าง)
ต้องตั้งค่า:
p:300                to set the interval between assignments to 5 minutes
ตัวเลือก (ทำการเลือก):
a:30-100             to add in numbers from 30-100 (optional)
s:10-100             to subtract in numbers from 10-100
m:10-20              to multiply in numbers from 10-20
d:200-400            to divide in numbers from 200-400
r:1-1000             to find square root in numbers from 1-1000
 
คำสั่งตัวอย่าง:
python3 '/path/to/mindpractice.py' p:300 d:10-100 s:10-30  r:300-600
เพื่อตั้ง:
p:300                to set the interval between assignments to 5 minutes
d:10-100             to divide in numbers from 10-100
s:10-30              to subtract in numbers from 10-30
r:300-600            to calculate square roots from 300-600
ในขณะที่การเพิ่มและการคูณไม่ได้ใช้
 
ดังนั้นในครั้งต่อไปหากสคริปต์รันด้วย:
python3 '/path/to/mindpractice.py'
มันจะจดจำข้อโต้แย้งที่ใช้ล่าสุด
ใช้รุ่นที่ตอบสนองความต้องการของคุณดีที่สุด ...