首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

Learn Python The Hard Way学习(35) - 旁支和函数

2012-07-19 
Learn Python The Hard Way学习(35) - 分支和函数前面我们已经学习了if,函数,list等,现在我们来转变思路,

Learn Python The Hard Way学习(35) - 分支和函数
前面我们已经学习了if,函数,list等,现在我们来转变思路,看看你能理解下面的代码吗?

运行结果root@he-desktop:~/mystuff# python ex35.py You are in a dark room.There is a door to your right and left.Which one do you take?> rightHere you see the great evil Cthulhu.He, it, whatever stares at you and you go insane.Do you flee for your life or eat your head?> ssHere you see the great evil Cthulhu.He, it, whatever stares at you and you go insane.Do you flee for your life or eat your head?> fleeYou are in a dark room.There is a door to your right and left.Which one do you take?> leftThere is a bear here.The bear has a bunch of honey.The fat bear is in front if another door.How are you going to move the bear?> taunt bearThe bear has moved from the door. you can go through it now.> taunt bearI got no idea what that means.> open doorThis room is full of fold. How much do you take?> 4Man, learn to type a number. Good job!root@he-desktop:~/mystuff# python ex35.py You are in a dark room.There is a door to your right and left.Which one do you take?> leftThere is a bear here.The bear has a bunch of honey.The fat bear is in front if another door.How are you going to move the bear?> taunt bearThe bear has moved from the door. you can go through it now.> open doorThis room is full of fold. How much do you take?> 1Nice, you are not greedy, you win!
加分练习1. 画一个游戏地图,看看你玩的流程。
2. 修改你的错误,包括拼写错误。
3. 为函数写评论,还记得doc文档吗?在函数里面第一行注释,包含在"""中。
4. 扩展你的游戏,你能简洁的扩展它吗?
5. 在gold_room中有一个很不好的方法去判断你输入的是不是数字,你能有更好的方法改进吗?参考int()方法。if nexe.isdigit():

热点排行