"print('Welcome!') g = input('Guess the number: ') guess = int(g) if guess == 5: print('You win!') else: print('You lose!') print('Game over!')"
"The editor saves the code you write into a file on your hard disk.The code(sometimes called the source code) is just text, and it can be written and read by humans.But computers can't process text meant for humans, at least not very well.That's why we need a tool to translate the human-friendly sour"
"Fortunately,Python3 comes with a built-in application called IDLE,which does both jobs and more.IDLE enables you to write and edit Python code,it translates this code into binary form, and finally, it runs the Python3 program.Because of this,IDLE is known as an Integrated Development Environment."
"A path refers to the set of instructions that the computer will actually follow(or excute). Your code is like a street network, with lots of sections of code connected together just like the streets in a city.When you drive through a city, you make decisions as to which streets you drive down by tur"
"Your program makes a decision using a branch condition.A branch condition has the value true or false.If the branch condition is true,it runs the code on the branch.And if the branch condition is false,it runs the code on the false branch."
"Python uses indents to connect a sequence of commands together to form paths.So how you connect branches together?You simply indent the second branch in by one more level.(Intends matter in python.Be careful how you indent code in Python;if you don't indent your code correctly,your code might do som"
"Loops are a little like branches.Just like branches, loops have a condition(the loop condition)that is either true or false.Also,like the if part of branches,if the loop condition is true, then a loop will run a given piece of code.For a branch,this code is called the body.For a loop,it's called the"
"from random import randint secret=randint(1,10) print('Welcome!') guess=0 while guess!=secret: g=input('Guess the number:') guess=int(g) if guess==secret: print('You win!') else: if guess >secret: print('Too high!') else: print('Too low!') print('Game over!')"
用户评论
想通过这本书来入门python,看完实在不尽人意。本书面向的应该是没有编程知识的初学者,但我相信一定会有不少迷惑的地方,不少应该详细解释的地方一笔带过,即使理解清楚又会花费不必要的时间(不是什么问题都需要去花费时间去理解的)。对于有编程经验的读者来说,该详细解释的基本特性只是略过,全篇笔墨着重在tkinter及pygame的应用和实现,对大多数人来说这两者都没那么重要(即使主力做GUI也不会使用tkinter,简陋的想哭,pygame更不用说),在写这些之前看了两章 head first python,比这本好太多,唯一缺点是的确需要一点点的语言基础。