Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagemath.github.io
Path: blob/master/eval/eberhart.json
2457 views
1
{
2
3
"Find the Nearest Point" : {
4
"cat" : ["Geometry", "Analytic"],
5
"descr" : "A mastery game for high school",
6
"code" : [
7
"x,y=var('x,y')",
8
"html('In the boxes below, enter the point $(a,b)$ on the line $c\\,x + d\\,y=8$ that is nearest the origin.<br>You may change the line. But if the cell becomes inactive, please click the Evaluate button to restart.')",
9
"def make_num(c,default):",
10
" try:",
11
" result=QQ(c)",
12
" except:",
13
" try:",
14
" result=RR(c)",
15
" except:",
16
" print('Only integers or fractions allowed, instead of %r'%c)",
17
" return default",
18
" return result",
19
"def make_lin(c,default):",
20
" try:",
21
" result=QQ(c)",
22
" except:",
23
" try:",
24
" result=RR(c)",
25
" except:",
26
" print('Only integers or fractions allowed, instead of %r'%c)",
27
" return default",
28
" if result < 1 or result > 5:",
29
" print('c and d should be between 1 and 5')",
30
" return default",
31
" return result",
32
"def check(a,b,c,d):",
33
" msg=['Good job','Sorry. Try again. Or change c and d to change the line.']",
34
" i=1",
35
" if d*a==b*c and c*a+d*b==8:",
36
" i=0",
37
" return(msg[i])",
38
"@interact",
39
"def levelc(a='1/2',b='7/3',c='2',d='3'):",
40
" a=make_num(a,1/2)",
41
" b=make_num(b,7/3)",
42
" c=make_lin(c,2)",
43
" d=make_lin(d,3)",
44
" print(check(a,b,c,d))",
45
" q=implicit_plot(c*x+d*y== 8, (x,-1,5),(y,-1,5))",
46
" r=line([[0,0],[c,d]],linestyle='--',color='turquoise')",
47
" p=point([0,0],color='red')",
48
" p1=point([a,b],color='green',size=12)",
49
" html('Calculate the point $(a,b)$ on $f(x,y)='+str(c)+'\\,x + '+str(3)+'\\,y = 8$ which is nearest the origin.')",
50
" show(p1+p+q+r,aspect_ratio=1,axes=true,figsize=4)"
51
]
52
}
53
}
54
55