加分习题
1. 把这个游戏的地图画出来,把自己的路线也画出来。
2. 改正你所有的错误,包括拼写错误。
3. 为你不懂的函数写注解。记得文档注解该怎么写吗?
4. 为游戏添加更多元素。通过怎样的方式可以简化并且扩展游戏的功能呢?
5. 这个 gold_room 游戏使用了奇怪的方式让你键入一个数字。这种方式会导致什么样的 bug?
你可以用比检查 0、1 更好的方式判断输入是否是数字吗?int() 这个函数可以给你一些头绪。
参考答案:
只需用next.isdigit()判断是否输入的为纯数字,然后int格式化,再和50判断大小
def gold_room():
print("This room is full of gold. How much do you take?")
next = raw_input("> ")
# if "0" in next or "1" in next:
if next.isdigit():
how_much =