微型python语法无效

格雷格

我正在为我的孩子们试用BBC微型教育计算机。我以为我会做一些简单的事情,例如遍历数组,使用按钮A和B左右增加(在末端循环)。我无法弄清楚我的代码有什么问题(在第3行报告语法错误)?我关于“​​输入→”和“基本→”的假设与顶部的微比特导入是否正确?

# Add your Python code here. E.g. from microbit import * function main () var alphabet := "" var alphabetIndex := 0 input → on button pressed(A) do if alphabetIndex = 1 then alphabetIndex := 27 else add code here end if alphabetIndex := alphabetIndex - 1 end input → on button pressed(B) do if alphabetIndex = 26 then alphabetIndex := 0 else add code here end if alphabetIndex := alphabetIndex + 1 end basic → forever do basic → show number(alphabetIndex, 150) end for 0 ≤ i < 1 do alphabetIndex := 1 alphabet := "ABCDEFGHIJKLMNOPQRSTUVWXYZ" end for basic → show string(alphabet[alphabetIndex], 150) end function

丹尼斯·施塔特诺夫(Dennis Shtatnov)

那是无效的Python代码。Python函数通常以def main():

前两行

# Add your Python code here. E.g.
from microbit import *`

是有效的python。

以下代码适用于BBC Micro的“ TouchDevelop”环境。制作一个新的代码文件,如果您想尝试并运行该代码,请确保选择TouchDevelop编辑器。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章