为什么要在教育领域使用Python?外文翻译资料

 2023-03-13 03:03

本科毕业设计(论文)

外文翻译

为什么要在教育领域使用Python?

作者:Nicholas H.Tollervey

国籍:美国

出处:OReilly Media, Inc

中文译文:(五号,宋体)

  我将回答一个非常简单的问题:Python语言本身的哪些特点使它适合于教育?这将涉及到学习一点Python和阅读一些代码。但如果你不是一个程序员,也不用担心!本章将使你大开眼界,了解到学习Python是多么容易。本章希望能让你大开眼界,了解学习Python是多么容易,以及,为什么它作为一种教学语言是如此受欢迎的选择。

 代码的可读性

  当我在一张纸上写下待办事项清单时,它看起来是这样的。

   购物

   修复破损的水沟

   修剪草坪

  这是一个明显的项目清单。如果我想把我的待办事项清单再细分一下,我可能会这样写。

   购物。

   鸡蛋

    培根

    西红柿

  修复破损的水沟。

  从隔壁借来的梯子

   寻找锤子和钉子

   返回梯子!

  修剪草坪。

   检查池塘周围的草坪是否有青蛙

   检查割草机燃料水平

  可以直观地理解成,主要任务被分解为子任务,这些子任务缩进到与其相关的主要任务下面。这使得我们很容易一目了然地看到这些任务之间的关系。

  

  这被称为范围界定。

  

  以这种方式缩进也是Python编写Python程序中定义的各种任务的方法。例如下面的代码,有一个叫做 say_hello 的函数,要求用户输入他们的名字,然后打印出一个友好的问候语。

  

  def say_hello():

  name = input(What is your name? )

  print(Hello, name)

  

  下面是这段代码的运行情况(包括用户输入)。

What is your name? Nicholas

Hello, Nicholas

注意实现say_hello函数的代码行是如何缩进的,就像待办事项清单一样。此外,代码中的每条指令都在自己的行上。这段代码很容易阅读和理解:只需看一下代码缩进的方式,就能明显看出哪几行代码是相互关联的。

  大多数其他计算机语言使用句法符号而不是缩进来表示范围。例如,许多语言,如Java、JavaScript和C都使用大括号和分号来表示。

  

  为什么这很重要?

  

  如果像我一样,你教过英语作为附加语言的学生或有特殊教育需要的学生,如阅读障碍,那么你会意识到,Python的直观缩进是全世界的人都能理解的(不管他们的语言背景如何)。缺乏混乱的符号,如散落在代码中的{、}和;,也使阅读Python代码变得容易得多。这样的缩进规则还可以指导你写下的代码应该是什么样子--学生们直观地了解如何展示他们的工作。

  与大多数其他语言相比,Python的语法(它的写法)是简单易懂的。例如,使用Perl编程语言编写的以下代码将在一个文本文件中寻找重复的单词。

  print '$.: doubled $_ ' while /(w )s 1/gi

  你能搞清楚Perl是如何做到这一点的吗?

  

  (为Perl辩解,它是一种神奇的强大的编程语言,其目的和目标与Python不同。这就是重点--你不会试图用詹姆斯-乔伊斯的《尤利西斯》来教一个人如何阅读,尽管它被广泛认为是20世纪最好的英语小说之一。)

  简单地说,因为你不必专注于如何阅读或编写Python代码,所以你可以把更多的精力放在真正理解它上。在教育背景下,任何能够降低参与编程所需努力的东西都是一件好事(实际上,可以说在所有背景下都是如此)。

简洁性

编写Python代码所需的简单核心概念和知识会让你走得很远。它们易于学习、使用和记忆是对Python有利的另一个特点。此外,Python 是一种明显的编程语言--它试图做预期的事情,如果你--程序员--试图做一些明显错误的事情,它会抱怨。它在第二种意义上也是明显的--它用通常理解的英语单词来命名各种概念。

  

  请考虑以下两个例子。

  

  在一些语言中,如果你想创建一个东西的列表,你必须使用各种命名的结构,如数组、数组列表、向量和集合。在 Python 中,你使用一种叫做列表的东西。这是我先前用 Python 写的待办事项清单。

  todo_list = [购物, 修复破损的水沟, 修剪草坪]

  这段代码为一个名为todo_list的对象分配了一个值列表,包含描述我待办事项列表中的任务的文字的字符串以及我可以在以后重复使用该对象来指代这个特定的列表项目。

  在一些语言中,如果你想创建一个数据字典,允许你存储和查询命名的值 (一个基本的键/值存储),你会使用称为 hashtables、关联数组、map 或 table 的结构。在 Python 中,你使用一种叫做字典的东西。

  这里有一小部分随机选择的首都城市的数据字典。

capital_cities = {

China: Beijing

Germany: Berlin,

Greece: Athens,

Russia: Moscow,

United Kingdom: London,

}

我简单地将字典分配给capital_citiesobject。如果我想查找某个国家的首都,我就在名为capital_cities的对象旁边的方括号中引用这个国家的名称。

capital_cities[China]

Beijing

  许多编程语言都有像 Python 的列表和字典一样的数据结构;其中一些语言做了很明显的事情,把这种结构称为 '列表 '和 '字典';还有一些语言使这种结构的使用像 Python 一样简单和明显 (尽管许多语言不是这样)。Python 的优势在于它做到了这三点:它把有用的数据结构作为语言的核心部分,给它们起了明显的名字,并使它们特别容易使用。这种有用性、简单性和明确性是消除参与编程的障碍的另一个案例。

  如前所述,Python 也会做预期的事情。例如,如果我试图把一个空字典和一个空列表相加 (这显然是错误的--证明我误解了我要做的事情) ,Python 会报错。

gt;gt;gt; {} []

Traceback (most recent call last):

File 'lt;stdingt;', line 1, in lt;modulegt;

TypeError: unsupported operand type(s) for : dict and list

这只是告诉我,我不能用 ' '操作数对一个字典和一个列表进行求和。这是意料之中的事,相当明显,而且相当有帮助。

  然而,其他语言试图不那么严格,对程序员更加宽容。虽然这听起来是个好主意,但这意味着像上面尝试的那种有问题的代码将被无误地执行,并导致不确定的结果(毕竟,将一个字典和一个列表相加的答案是什么?下面是无处不在的JavaScript语言在你试图添加相等的数据结构(用JavaScript的说法,就是一个对象{}和一个数组[])时将会做什么。

gt; {} []

0

  震惊,答案居然是零?!

  猜猜看,如果你试图在JavaScript中用一个对象对一个空数组求和,会发生什么(我们在求和的项之间进行交换)。

gt; [] {}

'[object Object]'

我敢打赌,你期待的是一个一致的结果!

  (同样,这里应该适用于JavaScript与Python有一套不同的目的和目标的警告)。

  学习,就其本质而言,涉及到犯错误和意识到已经犯的错误。只有这样才能调整行为,取得进步。如果你正在使用像JavaScript这样的语言学习编程(它宁愿对你的意思做出看似最好的猜测,而不是报告一个明显的错误),那么各种错误都会被忽略。相反,你要么继续你对编程世界的错误看法,要么你必须理解JavaScript用来使{} []等于0和[] {}等于'[对象Object]'的相当复杂和曲折的规则(本身就是一个很难完成的教育壮举)。

  Python的简单性和明显性鼓励学习者和专业开发者都去创建可理解的代码。可理解的代码更容易维护,而且不太可能包含错误(因为许多错误是由于误解了代码的实际作用,而不是你错误地认为它应该做什么)。能够在代码中简单地陈述你的想法是一种非常强大的能力。

  例如,考虑一个老式的文字冒险游戏。玩家在一个由地点组成的世界中游荡,这些地点有描述和通往其他地点的出口。下面的程序非常清楚和简单地实现了这一点。

  该程序的大部分内容要么是解释如何工作的注释,要么是描述游戏世界的数据字典。只有最后的代码块才真正定义了游戏的行为。我的预感是,即使你不是一个程序员,你也能得到它的工作要领。

'''

  一个用Python 3编写的非常简单的冒险游戏。

  世界 '是一个数据结构,描述我们想要探索的游戏世界。它是由描述地点的键/值字段组成的。每个地点都有一个描述和一个或多个通往其他地点的出口。这样的记录被实现为字典。

最后的代码创建了一个游戏 '循环',导致 在游戏中发生多个回合。每个回合显示 显示用户的位置,可用的出口,问用户下一步去哪里?下一步,然后对用户的输入作出适当的反应。输入做出适当的反应。

  '''

world = {

cave: {

description: You are in a mysterious cave.,

exits: {

up: courtyard,

},

},

tower: {

description: You are at the top of a tall tower.,

exits: {

down: gatehouse,

},

},

courtyard: {

description: You are in the castle courtyard.,

exits: {

south: gatehouse,

down: cave

},

},

gatehouse: {

description: You are at the gates of a castle.,

exits: {

south: forest,

up: tower,

north: courtyard,

},

},

forest: {

description: You are in a forest glade.,

exits: {

north: gatehouse,

},

},

}

# 设置一个默认的起点。

place = cave

 # 开始游戏的 '循环',它将不断产生新的回合。

while True:

#从世界范围内获取当前位置。

location = world[place]

# 输出该地点的描述和出口。

print(location[description])

print(Exits:)

print(, .join(location[exits].keys()))

#获取用户输入。

direction = input(Where now? ).strip().lower()

# 解析用户输入的信息...

if direction == quit:

print(By

剩余内容已隐藏,支付完成后下载完整资料


Why Python in Education?

I am going to answer a very simple question: which features of the Python language itself make it appropriate for education? This will involve learning a little Python and reading some code. But donrsquo;t worry if yoursquo;re not a coder! This chapter will hopefully open your eyes to how easy it is to learn Python (and thus, why it is such a pop‐ ular choice as a teaching language).

Code Readability

When I write a to-do list on a piece of paper, it looks something like this:

Shopping

Fix broken gutter

Mow the lawn

This is an obvious list of items. If I wanted to break down my to-do list a bit further, I might write something like this:

Shopping:

Eggs

Bacon

Tomatoes

Fix broken gutter:

Borrow ladder from next door

Find hammer and nails

Return ladder!

Mow the lawn:

Check lawn around pond for frogs

Check mower fuel level

Intuitively we understand that the main tasks are broken down into sub-tasks that are indented underneath the main task to which they relate. This makes it easy to see, at a glance, how the tasks relate to each other.

This is called scoping.

Indenting in this manner is also how Python organizes the various tasks defined in Python programs. For example, the following code simply says that there is a function called say_hello that asks the user to input their name, and then—you guessed it—prints a friendly greeting:

def say_hello():

name = input(What is your name? )

print(Hello, name)

Herersquo;s this code in action (including my user input):

What is your name? Nicholas

Hello, Nicholas

Notice how the lines of code implementing the say_hello function are indented just like the to-do list. Furthermore, each instruction in the code is on its own line. The code is easy to read and understand: it is obvious which lines of code relate to each other just by looking at the way the code is indented.

Most other computer languages use syntactic symbols rather than indentation to indicate scope. For example, many languages such as Java, JavaScript and C use curly braces and semicolons for this purpose.

Why is this important?

If, like me, you have taught students with English as an additional language or who have a special educational need such as dyslexia, then you will realize that Pythonrsquo;s intuitive indentation is something people the world over understand (no matter their linguistic background). A lack of confusing symbols such as {, } and ; scattered around the code also make it a lot easier to read Python code. Such indentation rules also guide how the code should look when you write it down—the students intuitively understand how to present their work.

Compared to most other languages, Pythonrsquo;s syntax (how it is written) is simple and easy to understand. For example, the following code written using the Perl programming language will look for duplicate words in a text document:

print '$.: doubled $_ ' while /(w )s 1/gi

Can you work out how Perl does this?

(In Perlrsquo;s defense, it is an amazingly powerful programming language with a different set of aims and objectives than Python. Thatrsquo;s the point—you wouldnrsquo;t try to teach a person how to read with James Joycersquo;s Ulysses, despite it being widely regarded as one of the top English-language novels of the 20th century.)

Put simply, because you donrsquo;t have to concentrate on how to read or write Python code, you can put more effort into actually understanding it. Anything that lowers the effort required to engage in programming is a good thing in an educational context (actually, one could argue that this is true in all contexts).

Obvious Simplicity

The simple core concepts and knowledge required to write Python code will get you quite far. That they are easy to learn, use and remember is another characteristic in Pythonrsquo;s favor. Furthermore, Python is an obvious programming language—it tries to do the expected thing and will complain if you, the programmer, attempt to do something clearly wrong. Itrsquo;s also obvious in a second sense—it names various concepts using commonly understood English words.

Consider the following two examples.

In some languages, if you want to create a list of things, you have to use variously named constructs such as arrays, arraylists, vectors and collections. In Python, you use something called a list. Herersquo;s my to-do list from earlier written in Python:

todo_list = [Shopping, Fix broken gutter, Mow the lawn]

This code assigns a list of values (strings of characters containing words that describe tasks in my to-do list) to an object named todo_list (which I can reuse later to refer to this specific list of

items).

In some languages, if you want to create a data dictionary that allows you to store and look up named values (a basic key/value store), yoursquo;d use constructs called hashtables, associative arrays, maps or tables. In Python, you use something called a dictionary.

Herersquo;s a data dictionary of a small selection of random capital cities:

capital_cities = {

China: Beijing

Germany: Berlin,

Greece: Athens,

Russia: Moscow,

United Kingdom: London,

}

Irsquo;ve simply assigned the dictionary to the capital_citiesobject. If I want to look up a capital city for a certain country, I reference the countryrsquo;s name in square brackets next to the object named capital_cities:

capital_cities[China]

Beijing

Many programming languages have data structures that work like Pythonrsquo;s lists and dictionaries; some of them do the obvious thing and call such constructs “lists” and “dictionaries”; some other languages m

剩余内容已隐藏,支付完成后下载完整资料


资料编号:[596500],资料为PDF文档或Word文档,PDF文档可免费转换为Word

您需要先支付 30元 才能查看全部内容!立即支付

课题毕业论文、文献综述、任务书、外文翻译、程序设计、图纸设计等资料可联系客服协助查找。