我正在寻找最酷的事情,你可以在几行简单的代码。我相信你可以用Haskell用15行写一个Mandelbrot集,但是很难理解。

我的目标是启发学生编程很酷。

我们知道编程很酷,因为你可以创造任何你想象到的东西——它是最终的创意出口。我想激励这些初学者,让他们尽可能多地克服早期学习的困难。

Now, my reasons are selfish. I'm teaching an Intro to Computing course to a group of 60 half-engineering, half business majors; all freshmen. They are the students who came from underprivileged High schools. From my past experience, the group is generally split as follows: a few rock-stars, some who try very hard and kind of get it, the few who try very hard and barely get it, and the few who don't care. I want to reach as many of these groups as effectively as I can. Here's an example of how I'd use a computer program to teach:

Here's an example of what I'm looking for: a 1-line VBS script to get your computer to talk to you: CreateObject("sapi.spvoice").Speak InputBox("Enter your text","Talk it") I could use this to demonstrate order of operations. I'd show the code, let them play with it, then explain that There's a lot going on in that line, but the computer can make sense of it, because it knows the rules. Then I'd show them something like this: 4(5*5) / 10 + 9(.25 + .75) And you can see that first I need to do is (5*5). Then I can multiply for 4. And now I've created the Object. Dividing by 10 is the same as calling Speak - I can't Speak before I have an object, and I can't divide before I have 100. Then on the other side I first create an InputBox with some instructions for how to display it. When I hit enter on the input box it evaluates or "returns" whatever I entered. (Hint: 'oooooo' makes a funny sound) So when I say Speak, the right side is what to Speak. And I get that from the InputBox. So when you do several things on a line, like: x = 14 + y; You need to be aware of the order of things. First we add 14 and y. Then we put the result (what it evaluates to, or returns) into x.

这就是我的目标,有一堆很酷的例子来演示,并在他们玩得开心的时候教他们。我在我室友身上尝试了这个例子,虽然我可能不会把它作为第一课,但她喜欢它,并学到了一些东西。

一些很酷的数学程序,可以做出漂亮的图形或容易理解的形状,这是很好的想法,我将研究这些。这里有一些复杂的actionscript示例,但这有点太高级了,我不能教flash。你还有什么其他的想法吗?


当前回答

我记得当我第一次开始编码循环总是让我印象深刻。您编写5 - 10行代码(或更少),然后打印出数百行(或无论您指定多少行)。(我首先学的是PHP和Java)。

for( int i = 0; i < 200; i++ )
{
   System.out.println( i );
}

其他回答

所以有一天,我觉得我受够了。我要学钢琴。看到像埃尔顿·约翰这样精通键盘的人,我确信这就是我想做的。

事实上,学钢琴是非常令人失望的。即使在完成了八年级的钢琴课程后,我仍然没有印象到,我弹钢琴的心理形象与我最初享受这项活动的想象有多么不同。

然而,我最喜欢的是我仅有的三年级音乐理论基础。我学到了音乐的构造。我终于能够从表演书面音乐的世界中走出来,开始创作自己的音乐。随后,我可以开始玩我想玩的东西了。


不要试图让新程序员眼花缭乱,尤其是年轻程序员。“少于十行简单代码”的整个概念似乎引起了一种“给我展示一些聪明的东西”的情绪。

你可以向新程序员展示一些聪明的东西。然后你可以教这个程序员如何复制这种“性能”。但这并不是他们迷上编程的原因。教他们一些基础知识,让他们自己合成十行聪明的代码。

我会向一个新程序员展示以下Python代码:

input = open("input.txt", "r")
output = open("output.txt", "w")

for line in input:
    edited_line = line
    edited_line = edited_line.replace("EDTA", "ethylenediaminetetraacetic acid")
    edited_line = edited_line.replace("ATP", "adenosine triphosphate")
    output.write(edited_line)

我意识到我不需要将line赋值给edited_line。然而,这只是为了让事情更清楚,并表明我没有编辑原始文档。

在不到十行里,我已经详尽地描述了一份文件。当然,还要确保向新程序员显示所有可用的字符串方法。更重要的是,我展示了我可以做的三件基本有趣的事情:变量赋值、循环、文件IO和使用标准库。

我想您会同意这段代码并不令人眼花缭乱。事实上,这有点无聊。不,实际上,很无聊。但是将代码展示给一个新的程序员,看看这个程序员是否能够在一周内(如果不是当天的话)将脚本的每个部分重新用于更有趣的内容。当然,您可能不喜欢(可能使用这个脚本来创建一个简单的HTML解析器),但其他一切都需要时间和经验。

我给有学习障碍的11-12岁学生上过课。我们使用Hypercard,他们发现他们可以记录物体(图像,盒子等)的位置,因为他们移动它,并播放它(动画)。虽然这不是编码,但他们想做的是:删除其中一个动作,而不重新记录它。我告诉他们,他们必须去查看代码并修改它。

你可以看出谁有计算机/编程的诀窍,当他们更喜欢用代码来做的时候,因为他们有更多的控制权。

在Excel中做一个复杂的宏,然后学习代码在做什么,这可能是通往VBA的门户。

根据年龄群体或兴趣水平的不同,直接进入代码可能很难,但最终是重要的。

你可以创建一个选择随机数的应用程序。你得猜一下。如果你错了,它会说:更高或更低。如果你猜对了,这是个不错的消息。

为学生们演奏很酷。

简单的Python版本,没有适当的错误检查:

import random

while input('Want to play higher/lower? ').lower().startswith('y'):
    n = random.randint(1, 100)
    g = int(input('Guess: '))

    while g != n:
        print('  %ser!' % (g > n and 'low' or 'high'))
        g = int(input('Guess: '))

    print('  Correct! Congratulations!')

埃里克建议让电脑猜数字。这也可以在10行代码内完成(尽管现在缺乏适当的错误检查更加严重:在范围之外的有效数字会导致无限循环):

while input('Want to let the pc play higher/lower? ').lower().startswith('y'):
    n = int(input('Give a number between 1 and 100: '))
    lo, hi, guess, tries = 1, 100, 50, 1

    while guess != n:
        tries += 1
        lo, hi = (guess + 1, hi) if guess < n else (lo, guess - 1)
        guess = (lo + hi) // 2

    print('Computer guessed number in %d tries' % tries)

小书签怎么样?它将向他们展示如何操作他们每天使用的东西(互联网),而不需要任何开发工具。

就像……

10 rem twelve times table

20 For x = 1 to 12

30  For y = 1 to 12

40     print using"####";x*y;

50  next y

60  print 

70 next x

80 end