Hello! This is a book that will teach you how to program by showing you how to create
When I was a kid, I found a book like this that taught me how to write my first programs and games. It was fun and easy. Now as an adult, I still have fun programming computers, and I get paid for it. But even if you don't become a computer programmer when you grow up, programming is a useful and fun
Computers are very useful machines. The good news is that learning to program a computer is easy. If you can read this book, you can program a computer. A computer program is just a bunch of instructions run by a computer, just like a storybook is just a whole bunch of
These instructions are like the turn-by-turn instructions you might get for
In this book, any words you need to know will look like this. For example, the word "program" is defined in the previous paragraph.
In order to tell a computer what you want it to do, you write a program in a language that the computer understands. The programming language this book teaches is named Python. There are many different programming languages including BASIC, Java, Python, Pascal, Haskell, and C++ (pronounced, "c plus plus").
When I was a kid most people learned to program in BASIC as their first language. But new programming languages have been invented since then, including Python. Python is even easier to learn than BASIC and it's a serious programming language used by professional computer programmers. Many adults use Python in their work (and when programming just for fun).
The first few games we'll create together in this book will probably seem simple compared to the games you've played on the Xbox, Playstation, or Wii. They don't have fancy graphics or music but that's because they're meant to teach you the basics. They're purposely simple so that we can focus on learning to program. Games don't have to be complicated to be fun. Hangman,
We'll also learn how to make the computer solve some math problems in the Python shell. (Don't worry if you don't know a lot of
Before we can begin programming you'll need to install the Python software; specifically the Python interpreter. (You may need to ask an adult for help here.) The interpreter is a program that understands the instructions that you'll write in the Python language. Without the interpreter, your computer won't understand these instructions and your programs won't work. (We'll just refer to "the Python interpreter" as "Python" from now on.)
Because we'll be writing our games in the Python language, we need to download Python first, from the official website of the Python programming language, http://www.python.org
I'm going to give you instructions for installing Python on Microsoft Windows, not because that's my favorite operating system but because chances are that's the operating system that your computer is running. You might want the help of someone else to download and install the Python software.
When you get to python.org, you should see a list of links on the left (About, News, Documentation, Download, and so on.) Click on the Download link to go to the download page, then look for the file called Python 3.1 Windows Installer (Windows binary --does not include source) and click on its link to download Python for Windows.
(рис 1.1) Click the Windows installer link to download Python for Windows from http://www.python.org
Double-click on the python-3.1.msi file that you've just downloaded to start the Python installer. (If it doesn't start, try right-clicking the file and choosing Install.) Once the installer starts up, click the Next button and just accept the choices in the installer as you go (no need to make any changes). When the install is finished, click Finish.
The installation for Mac OS is similar. Instead of downloading the .msi file from the Python website, download the .dmg Mac Installer
If your operating system is Ubuntu, you can install Python by opening a terminal window (click on Applications > Accessories > Terminal) and entering sudo then pressing Enter. You will need to enter the root password to install Python, so ask the person who owns the computer to type in this password.
There may be a newer version of Python available than 3.1. If so, then just download the latest version. The
A video tutorial of how to install Python is available from this book's website at http://inventwithpython.com/videos/.
If your operating system is Windows XP, you should be able to run Python by choosing Start > Programs > Python 3.1 > IDLE (Python GUI). When it's running it should looking something like Figure 1.2. (But different operating systems will look slightly different.)
(рис 1.2) The IDLE program's interactive shell on Windows.
IDLE stands for Interactive DeveLopment Environment. The development environment is software that makes it easy to write Python programs. We will be using IDLE to type in our programs and run them.
The window that appears when you first run IDLE is called the interactive shell. A shell is a program that lets you type instructions into the computer. The Python shell lets you type Python instructions, and the shell sends these instructions to software called the Python interpreter to perform. We can type Python instructions into the shell and, because the shell is interactive, the computer will read our instructions and
There are a few things you should understand about this book before you get started. "Invent with Python" is different from other programming books because it focuses on the complete source code for different games. Instead of
Most chapters begin with a sample run of the featured program. This sample run shows you what the program's output looks like, with what the user types in shown as bold print. This will give you an idea of what the complete game will look like when you have entered the code and run it.
Some chapters also show the complete source code of the game, but remember: you don't have to enter every line of code right now. Instead, you can read the chapter first to understand what each line of code does and then try entering it later.
You can also download the source code file from this book's website. Go to the URL http://inventwithpython.com/source and follow the instructions to download the source code file.
When entering the source code yourself, do not type the line numbers that appear at the beginning of each line. For example, if you see this in the book:
9. number = random.randint(1, 20)
You do not need to type the "9." on the left side, or the space that immediately follows it. Just type it like this:
number = random.randint(1, 20)
Those numbers are only used so that this book can refer to specific lines in the code. They are not a part of the actual program.
Aside from the line numbers, be sure to enter the code exactly as it appears. Notice that some of the lines don't begin at the
For example, you can see that the second line is indented by four spaces because the four characters ("whil") on the line above are over the indented space. The third line is indented by another four spaces (the four characters, "if n" are above the third line's indented space):
while guesses < 10:
if number == 42:
print('Hello')
Some lines of code are too long to fit on one line on the page, and the text of the code will wrap around to the next line. When you type these lines into the file editor, enter the code all on one line without pressing Enter.
You can tell when a new line starts by looking at the line numbers on the left side of the code. For example, the code below has only two lines of code, even though the first line wraps around:
1. print('This is the first line! xxxxxxxxxxxxxxxxxxxxxxxxxxx')
2. print('This is the second line! ')
You can visit http://inventwithpython.com/traces to see a trace through each of the programs in this book. Tracing a program means to step through the code one line at a time, in the same way that a computer would execute it. The traces web page has notes and helpful reminders at each step of the trace to explain what the program is doing, so it can help you better understand why these programs work the way they do.
Some of the games in this book are a little long. Although it is very helpful to learn Python by typing out the source code for these games, you may accidentally make typos that cause your
You can copy and paste the text of your source code to the online diff tool on the book's website. The diff tool will show any differences between the source code in the book and the source code you've typed. This is an easy way of finding any typos in your program.
Copying and pasting text is a very useful computer
The online diff tool is at this web page: http://inventwithpython.com/diff. A video tutorial of how to use the diff tool is available from this book's website at http://inventwithpython.com/videos/.
This chapter has helped you get started with the Python software by showing you the python.org website where you can download it for free. After installing and starting the Python IDLE software, we will be ready to learn programming starting in the next chapter.
This book's website at http://inventwithpython.com has more information on each of the chapters, including an online tracing website that can help you understand what exactly each line of the programs do.
Для получения официальных документов о завершении программы дополнительного профессионального образования (удостоверения о повышении квалификации, дипломов о профессиональной переподготовке и MBA) необходимо предоставить:
Внимание! Вы можете не заказывать доставку бумажной версии официального документы, а скачать его в электронном виде и распечатать самостоятельно. Информация о выданном документе в течение 1 месяца загружается в Федеральную информационную систему «Федеральный реестр сведений о документах об образовании и (или) о квалификации, документах об обучении» - ФИС ФРДО.
Доступ на новый сайт осуществляется с использованием адреса электронной почты, который был указан вами при регистрации на "старом". Мы постарались перенести все ваши данные с прежнего ресурса, однако не исключена вероятность потери части информации.
При возникновении проблемы со входом, воспользуйтесь функцией сброса пароля
Если вы обнаружите несоответствия, пожалуйста, сообщите нам.