Invent Your Own Computer Games with Python(第二版)(第一章(上))

第一章(上)

 

安装python

本章重点:

l  下载和安装python

l  用IDLE来运行python命令

l  怎样阅读本书

l  本书网站http://inventwithpython.com

  大家好,这是一本通过编写电脑游戏来教你编程技巧的书。一旦你知道了本书中所说的游戏是怎样运行的,你就可以来编写你自己的电脑游戏了。你只需要一台电脑,一个叫做Python解释器的软件和这本书。该软件是免费的,你可以从网上下载。

  当我还是小孩的时候,我就阅读了一本就像该书一样教会我编写自己的程序和游戏的书。那本书简单有趣,我现在仍旧对编程充满了兴趣,并且以编程为生。但是,即使你长大后没有成为一个程序员,编程也应该是该我们掌握的一项有用并且有趣的技能。

  计算机是一个非常有用的机器。庆幸的是学习编程是简单的 。如果你阅读了本书,你就可以编程了。程序就是一连串的能被电脑执行的指令,就像是读者一句一句的读故事书那样。

  电脑指令就如同你步行去你朋友家的线路指令一样(向左转,走过两个街道,一直走,直到你看到你右边的第一个蓝房子)。电脑只是按照你给的指令的次序去执行,

  为了使电脑能够按照你的意图去做事,你必须用一些电脑能够理解的语言。这种语言就是Python。有很多的编程语言,包括BASIC、Java、Pascal和C++

  我小的时候,有很多人把BASIC作为他们学习的第一门编程语言。现在一些新的编程语言出现了,这其中包括Python。Python是比BASIC还容易学习的编程语言,并且它是被很多专业的编程人员使用的语言。很多人在他们的工作中使用Python。

  本书刚开始的几个例子比你在Xbox,Playstation或者Wii上玩的游戏简单很多。它们没有有趣的画面和音乐,因为它们只是教你一些编程基础。我们只是注重于学习一些程序,所以这些游戏都很简单没有很大的趣味。如Hangman、Tic Tac Toe和making secret codes。

  我们也学习用Python shell 来解决一些数学问题。

 

下载和安装Python

在我们开始编程之前,我们需要安装一个叫做Python 解释器的软件。解释器就是一个能够理解你所写的Python指令的程序。没有该解释器电脑就不会理解你写的Python指令。

因为我们将用Python编写游戏,所以应该先从Python的官网http://www.python.org)下载Python。

我将会指导你下在Windows上安装Python,但这并代表windows是我喜欢的操作系统,因为你的电脑安装的是windows。

当你登录python.org网站后,你可能会在左边看到很多链接(About、News、Documentation、Download等等)点击Download链接进入下载页面。然后找一个为Python 3.1 Windows Installer(现在最新的版本为Python 3.2.2)的文件


Figure1-1


  双击python-3.1.msi文件你就可以下载python安装包了。

 

 

特别注意:你要确保你下载安装的是python3而不是python2.本书的所有程序都是基于python3的,如果你用的是python2的话,程序运行时将会出错。

在Mac os上安装也是一样的,先从python站点下载.msi文件,然后安装。该文件的链接是“Mac Installer disk imag (3.1.1)”.

 

如果你的操作系统是Ubuntu,你可以通过终端来安装(点击应用程序-->附件-->终端),再输入sudo apt-get install python3。

你可能得到比python3.1更新的版本(我翻译时的python3.2.2刚发布),这样的话你下载安装最新的版本就可以了。如果在安装的时候你有什么问题的话,你可以在google中输入“installing Python on<your operating system's name”。Python是一种非常流行的编程语言,所以你很容易的就能找到帮助文档。

 http://inventwithpython.com/videos/ ,在该网站上你可以得到python的安装视频。.

 




####################################################################################################################################

####说明:

#######python的确是一种功能强大的编程语言,至于它的强大之处我也不说了,因为别人说的已经够多了。

#######该书是我从网上看到的,我们可以在网上免费阅读本书,这本书写的非常简单,很容易理解。对于以前没有接触过编程并且想学习编程的人来说是很好的书,如果有一定的英语基础的话,我还是建议去读英文原版,东西毕竟还是原汁原味的好!!呵呵。。。

######我也是为打发时间来翻译本书的,有很多地方翻译的还不是很好,希望看到的人能够提出宝贵的意见!

 


 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Who is this book for? ?Anyone who wants to teach themselves computer programming, even if they have no previous experience programming. ?Kids and teenagers who want to learn computer programming by programming games. Kids as young as 9 or 10 years old should be able to follow along. ?Adults and teachers who wish to teach others programming. ?Programmers who want to teach others "real" programming by example. This book is available for free under a Attribution/Share-Alike Creative Commons license. You can make as many copies of it as you like, as long as credit to the author is left in. The Python programming language software this book teaches is also freely available from www.python.org. Table of Contents Chapter 1 - "Hello World!" - Your First Program x Hello! x Downloading and Installing Python x Starting the Python Interpreter x Some Simple Math Stuff x Evaluating Expressions x Variables x Strings x Writing Programs x Hello World! x The Difference Between Statements and Expressions x "My Favorite Stuff" x Crazy Answers and Crazy Names for our Favorite Stuff x Capitalizing our Variables x Chapter 2 - Guess the Number x Source Code x Arguments x Blocks x Conditions and Booleans x if Statements x Step by Step, One More Time x Some Changes We Could Make x What Exactly is Programming? x A Web Page for Program Tracing x Chapter 3 - Jokes x How Programs Run on Computers x Source Code x Some Other Escape Characters x Quotes and Double Quotes x Chapter 4 - Dragon Realm x Source Code x def Statements x Boolean Operators x Variable Scope x Parameters x Local Variables and Global Variables with the Same Name x Where to Put Function Defintions x The Colon : x Step by Step, One More Time x Designing the Program x A Web Page for Program Tracing x Chapter 5 - Hangman x ASCII Art x Source Code x Designing the Program x Multi-line Strings x Constant Variables x Lists x Changing the Values of List Items with Index Assignment x List Concatenation x The in Operator x Removing Items from Lists with del Statements x Lists of Lists x Methods x The len() Function x The range() Function x for Loops x Strings Act Like Lists x List Slicing and Substrings x elif ("Else If") Statements x And that's it! x Dictionaries x Sets of Words for Hangman x Chapter 6 - Tic Tac Toe x Source Code x Designing the Program x Game AI x List References x Short-Circuit Evaluation x The None Value x A Web Page for Program Tracing x Chapter 7 - Bagels x Source Code x Augmented Assignment Operators x The sort() List Method x The join() String Method x String Interpolation x Chapter 8 - Sonar x Grids and Cartesian Coordinates x Negative Numbers x Changing the Signs x Absolute Values x Coordinate System of a Computer Monitor x Source Code x Designing the Program x The remove() List Method x Chapter 9 - Caesar Cipher x About Cryptography x ASCII, and Using Numbers for Letters x The chr() and ord() Functions x Source Code x The isalpha() String Method x The isupper() and islower() String Methods x Cryptanalysis x Brute Force x Chapter 10 - Reversi x How to Play Reversi x Source Code x The bool() Function x The random.shuffle() Function x Tips for Inventing Your Own Games x Chapter 11 - AI Simulation x "Computer vs. Computer" Games x Percentages x Integer Division x The round() Function x Learning New Things by Running Simulation Experiments x

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值