笨方法学Python笔记(5)

来源:互联网 发布:多益网络面试经验 编辑:程序博客网 时间:2024/05/29 13:14

上次进行到习题29,习题30中回答了之前29中给出问题的答案,以及强化了if语句使用,内容比较少,因此敲了一遍代码直接进行到习题31。


习题31,先上代码,从代码中可以发现作者不仅逗比,还挺吓人,喜欢写恐怖故事。

print "You enter a dark room with two doors.Do you go through the door #1 or door #2?"door = raw_input(">")if door == "1":print "There is a giant bear here eating a cheese cake. What do you do?"print "1.Take the cake."print "2. Scream at the bear."bear = raw_input(">")if bear =="1":print "The bear eats your face off. Good job!"elif bear =="2":print "The bear eats your legs off. Good job!"else:print "Well,doing %s is probably better.Bear runs away."elif door =="2":print "You stare into the endless abyss at Cthulhu's retina."print "1.Blueberries."print "2.Yellow jacket clothespins."print "3. Understanding revolvers yelling melodies."insanity = raw_input("> ")if insanity == "1" or insanity =="2":print "Your body survives powered by a mind of jello.Good job!"else:print "The insanity rots your eyes into a pool of muck.Good job!"else:print "You stumble around and fall on a knife and die.ood job!"


这个例子是一个小文字游戏,输入数字进入不同的故事章节。游戏有点吓人,不建议16周岁以下的宝宝玩,好怕怕,容易做噩梦。突然想到,昨天晚上做了一个噩梦,梦见和法老大战,怎么也杀不死,最后只能压在棺材里。哦,扯远了,还是回来接着学习吧,毕竟是学习笔记,不是日记,等有空重新开个博专心写日记。

这一部分主要是练习if嵌套if语句,让逻辑分支更丰满,也就更好玩。接下来进入加分习题。

---------------------------------------------------------------------------------------------------------------------------------------------------------

加分习题:为游戏添加新的部分,改变玩家做决定的位置。尽自己的能力扩展这个游戏,不过别把游戏弄得太怪异了。

What??!!加分习题竟然是添加新的部分,还不让把游戏弄得诡异??!已经很诡异了好么?这样画风难道让我变出个Hello Kitty消灭怪兽,然后和多啦A梦幸福快乐地生活在一起?


算了,毕竟还要跟着人家学python,忍忍就过去了。还是乖乖贴代码。

print "You enter a dark room with two doors.Do you go through the door #1 or door #2?"door = raw_input(">")if door == "1":print "There is a giant bear here eating a cheese cake. What do you do?"print "1.Take the cake."print "2.Scream at the bear."print "3.Run away immediately."bear = raw_input(">")if bear =="1":print "The bear eats your face off. Good job!"elif bear =="2":print "The bear eats your legs off. Good job!"elif bear == "3":print "You run into Doraemon!"print "1.Tell him that you could give dorayakis to him, if he kills the bear behind."print "2.Tell him that Hello Kitty is kidnapped by the bear behind."how_to_do = raw_input("> ")if how_to_do == "1":print "Doraemon has just eaten many dorayakis, he declines and goes away. Unfortunately, you will die."elif how_to_do =="2":print "To save the Hello Kitty, Doraemon kills the bear. However, you lie to him and he cuts your tonge as a punishment."else:print "Well,doing %s is probably better.Bear runs away."elif door =="2":print "You stare into the endless abyss at Cthulhu's retina."print "1.Blueberries."print "2.Yellow jacket clothespins."print "3. Understanding revolvers yelling melodies."insanity = raw_input("> ")if insanity == "1" or insanity =="2":print "Your body survives powered by a mind of jello.Good job!"else:print "The insanity rots your eyes into a pool of muck.Good job!"else:print "You stumble around and fall on a knife and die.ood job!"


新增加了碰到哆唻A梦的情节,反正都不是好结局,来啊,互相伤害啊。


原创粉丝点击