【发布时间】:2016-08-21 01:09:44
【问题描述】:
我正在尝试为我的 TI-84 编写一个基本程序,用于查找 2d 平面上的多边形面积。作为参考,我用python写过很多次了,这是它的作用:
x_list,y_list,verts,tot_1,tot_2=[],[],int(input("How many vertices are on the polygon: ")),0,0 //sets vars to defaults and gets num of vertices
for i in range(verts): //gets X and Y values of each point for num. of vertices
x_list.append(float(input("X value of point %s: " % str(i+1)))) //appends x value given to x list
y_list.append(float(input("Y value of point %s: " % str(i+1)))) //appends y value given to y list
for ind in range(verts-1):
tot_1 += (x_list[ind]*y_list[ind+1])-(y_list[ind]*x_list[ind+1])
print(str(abs((tot_1)/2))) //prints area: abs value of total over two
这只是执行常规数学中也显示的非常基本的算法:http://www.mathopenref.com/coordpolygonarea.html
现在,当我尝试在 TI-Basic 中编写相同的内容(使用 TI Connect 应用程序并发送到计算器)时,它会在第一次引用其中一个列表时返回语法错误; “检查输入的所有参数”。这条线被星号包围。 cmets不在实际代码中
ClrHome //clears screen
Prompt V //gets number of vertices
0→T //sets total to 0
Disp V //displays vertices, was used for testing
For(N,1,V,1) //runs code for number of vertices
Input "x val: ",X //gets latest x val
Input "y val: ",Y //gets latest y val
**X→L1(1+dim(L1))** //appends x to listand
Y→L2(1+dim(L2)) //y to list
End //end for
For(I,1,P,1)
T+((L1(I)*L2(I+1))-(L2(I)*L1(I+1))→T //adds up total
End
Disp abs(T/2)
当通过将 L1 更改为 list1 字符并将 L2 更改为 list2 字符来更改计算器上的代码时,它所做的只是返回值 12.5*number of vertices-2。我的问题是:
- 如何在计算机上的代码中表示列表?当我在代码中写 L1 时,它实际上不是我认为的内置列表变量,这就是导致语法错误的原因。我认为。
- 我需要重置列表变量吗?我第一次测试这个时, 12.5*vertices-2 起作用了,所以它只是将列表变量永久设置为那个,现在当它在程序的以后运行中添加东西到列表时,它永远不会达到那些索引?
- 代码是否存在任何缺陷,导致其根本无法工作?我对 TI-Basic 完全陌生。
【问题讨论】: