博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
EX35
阅读量:5066 次
发布时间:2019-06-12

本文共 3433 字,大约阅读时间需要 11 分钟。

1 from sys import exit 2  3 def gold_room(): 4     print "This room is full of gold. How much do you take?" 5      6     next = raw_input("> ") 7     if "0" in next or "1" in next: 8         how_much = int(next) 9     else:10         dead("Man, learn to type a number.")11         12         if how_much < 50:13             print "Nice, you're not greedy, you win!"14             exit(0)15         else:16             dead("You greedy bastard!")17             18         19 def bear_room():20     print "There is a bear here."21     print "The bear has a bunch of honey."22     print "The fat bear is in front of another door."23     print "How are you going to move the bear?"24     bear_moved = False25     26     while True:27         next = raw_input("> ")28         29         if next == "take honey":30             dead("The bear looks at you then slaps your face off.")31         elif next == "taunt bear" and not bear_moved:32             print "The bear has moved from the door. You can go through it now."33             bear_moved = True34         elif next == "taunt bear" and bear_moved:35             dead("The bear gets pissed off and chews your leg off.")36         elif next == "open door" and bear_moved:37             gold_room()38         else:39             print "I got no idea what that means."40     41     42 def cthulhu_room():43     print "Here you see the great evil Cthulhu."44     print "He, it, whatever stares at you and you go insane."45     print "Do  you flee for your life or eat your head?"46     47     next = raw_input("> ")48     49     if "flee" in next:50         start()51     elif "head" in next:52         dead("Well that was tasty!")53     else:54         cthulhu_room()55         56         57 def dead(why):58     print why, "Good job!"59     exit(0)60     61 def start():62     print "You are in a dark room."63     print "There is a door to your right and left."64     print "Which one do you take?"65     66     next = raw_input("> ")67     68     if next == "left":69         bear_room()70     elif next == "right":71         cthulhu_room()72     else:73         dead("You stumble around the room until you starve.")74         75         76 start()

类似迷宫开门游戏,通过不断输入关键字进入最终的gold_room。

疑问:

1、int()起到的用途

Help on class int in module __builtin__:class int(object) |  int(x=0) -> int or long |  int(x, base=10) -> int or long | |  Convert a number or string to an integer, or return 0 if no arguments |  are given.  If x is floating point, the conversion truncates towards zer |  If x is outside the integer range, the function returns a long instead. | |  If x is not a number or if base is given, then x must be a string or |  Unicode object representing an integer literal in the given base.  The |  literal can be preceded by '+' or '-' and be surrounded by whitespace. |  The base defaults to 10.  Valid bases are 0 and 2-36.  Base 0 means to |  interpret the base from the string as an integer literal. |  >>> int('0b100', base=0) |  4 | |  Methods defined here: | |  __abs__(...) |      x.__abs__() <==> abs(x) | |  __add__(...) |      x.__add__(y) <==> x+y | |  __and__(...) |      x.__and__(y) <==> x&y | |  __cmp__(...) |      x.__cmp__(y) <==> cmp(x,y) | |  __coerce__(...) |      x.__coerce__(y) <==> coerce(x, y) | |  __div__(...) |      x.__div__(y) <==> x/y | |  __divmod__(...)

2、dead()的用途:就是死亡的意思= =

3、start()用途:开始的意思= =

 

转载于:https://www.cnblogs.com/LevenLau/p/6384405.html

你可能感兴趣的文章
控制文件的备份与恢复
查看>>
软件目录结构规范
查看>>
mysqladmin
查看>>
解决 No Entity Framework provider found for the ADO.NET provider
查看>>
设置虚拟机虚拟机中fedora上网配置-bridge连接方式(图解)
查看>>
[置顶] Android仿人人客户端(v5.7.1)——人人授权访问界面
查看>>
ES6内置方法find 和 filter的区别在哪
查看>>
Android实现 ScrollView + ListView无滚动条滚动
查看>>
java学习笔记之String类
查看>>
UVA 11082 Matrix Decompressing 矩阵解压(最大流,经典)
查看>>
硬件笔记之Thinkpad T470P更换2K屏幕
查看>>
iOS开发——缩放图片
查看>>
HTTP之URL的快捷方式
查看>>
满世界都是图论
查看>>
配置链路聚合中极小错误——失之毫厘谬以千里
查看>>
代码整洁
查看>>
蓝桥杯-分小组-java
查看>>
Android Toast
查看>>
iOS开发UI篇—Quartz2D使用(绘制基本图形)
查看>>
docker固定IP地址重启不变
查看>>