马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 shinemic 于 2017-8-9 23:24 编辑
甲鱼哥把我吓到了... 一开始就让我们做出植物大战僵尸? WTF?
就知道机(wei)智(suo)的甲鱼跟我们开玩笑, 后面言归正传了起来.
假装打开 IDLE (其实是在 Linux 打开了 Vim 开刷), 洋洋洒洒写入文件 wordgame_1.py (强烈建议论坛发帖支持 markdown!!!!)
- # -*- coding: utf-8 -*-
- print('---------------我爱鱼C工作室---------------')
- temp = input('不妨猜下小甲鱼现在心理想的是哪个数字: ') # 我特么哪知道
- guess = int(temp)
- if guess == 8:
- print('卧槽, 你特么是小甲鱼心里的蛔虫么?!')
- print('哼, 猜中了也没有奖励') # 打字的时候起一身鸡皮疙瘩
- else:
- print('猜错啦, 小甲鱼现在心理想的是8!')
- print('游戏结束, 不玩了不玩了!')
复制代码 输出如下:
- ▶ python wordgame_1.py
- ---------------我爱鱼C工作室---------------
- 不妨猜下小甲鱼现在心理想的是哪个数字: 9
- 猜错啦, 小甲鱼现在心理想的是8!
- 游戏结束, 不玩了不玩了!
- ▶ python wordgame_1.py
- ---------------我爱鱼C工作室---------------
- 不妨猜下小甲鱼现在心理想的是哪个数字: 8
- 卧槽, 你特么是小甲鱼心里的蛔虫么?!
- 哼, 猜中了也没有奖励
- 游戏结束, 不玩了不玩了!
复制代码 input, int 都是内置函数 (BIF, Built-in Functions), 打印完提示语句之后 temp 存储来自用户的输入 (暂不清楚被存储为什么类型 ) 那么后面把这个东西转换为整型, 后面经过一个简单的判断流程, 等于提前设定好的8如何如何, 不等于8如何如何.
甲鱼哥最后讲解了 BIF, 罗列下:
- >>> dir(__builtins__)
- ['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException', 'BlockingIOError', 'BrokenPipeError', 'BufferError', 'BytesWarning', 'ChildProcessError', 'ConnectionAbortedError', 'ConnectionError', 'ConnectionRefusedError', 'ConnectionResetError', 'DeprecationWarning', 'EOFError', 'Ellipsis', 'EnvironmentError', 'Exception', 'False', 'FileExistsError', 'FileNotFoundError', 'FloatingPointError', 'FutureWarning', 'GeneratorExit', 'IOError', 'ImportError', 'ImportWarning', 'IndentationError', 'IndexError', 'InterruptedError', 'IsADirectoryError', 'KeyError', 'KeyboardInterrupt', 'LookupError', 'MemoryError', 'ModuleNotFoundError', 'NameError', 'None', 'NotADirectoryError', 'NotImplemented', 'NotImplementedError', 'OSError', 'OverflowError', 'PendingDeprecationWarning', 'PermissionError', 'ProcessLookupError', 'RecursionError', 'ReferenceError', 'ResourceWarning', 'RuntimeError', 'RuntimeWarning', 'StopAsyncIteration', 'StopIteration', 'SyntaxError', 'SyntaxWarning', 'SystemError', 'SystemExit', 'TabError', 'TimeoutError', 'True', 'TypeError', 'UnboundLocalError', 'UnicodeDecodeError', 'UnicodeEncodeError', 'UnicodeError', 'UnicodeTranslateError', 'UnicodeWarning', 'UserWarning', 'ValueError', 'Warning', 'ZeroDivisionError', '__build_class__', '__debug__', '__doc__', '__import__', '__loader__', '__name__', '__package__', '__spec__', 'abs', 'all', 'any', 'ascii', 'bin', 'bool', 'bytearray', 'bytes', 'callable', 'chr', 'classmethod', 'compile', 'complex', 'copyright', 'credits', 'delattr', 'dict', 'dir', 'divmod', 'enumerate', 'eval', 'exec', 'exit', 'filter', 'float', 'format', 'frozenset', 'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex', 'id', 'input', 'int', 'isinstance', 'issubclass', 'iter', 'len', 'license', 'list', 'locals', 'map', 'max', 'memoryview', 'min', 'next', 'object', 'oct', 'open', 'ord', 'pow', 'print', 'property', 'quit', 'range', 'repr', 'reversed', 'round', 'set', 'setattr', 'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple', 'type', 'vars', 'zip']
复制代码 嗯. 好多, 甲鱼哥应该会在后续的课程里面一步步讲解这个 BIF
|