鱼C论坛

 找回密码
 立即注册
查看: 2057|回复: 0

[技术交流] 「零基础入门学习Python」学习笔记 - 002 - 猜数字游戏

[复制链接]
发表于 2017-8-9 18:20:34 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 shinemic 于 2017-8-9 23:24 编辑

甲鱼哥把我吓到了... 一开始就让我们做出植物大战僵尸? WTF?
就知道机(wei)智(suo)的甲鱼跟我们开玩笑, 后面言归正传了起来.
假装打开 IDLE (其实是在 Linux 打开了 Vim 开刷), 洋洋洒洒写入文件 wordgame_1.py (强烈建议论坛发帖支持 markdown!!!!)
  1. # -*- coding: utf-8 -*-

  2. print('---------------我爱鱼C工作室---------------')
  3. temp = input('不妨猜下小甲鱼现在心理想的是哪个数字: ') # 我特么哪知道
  4. guess = int(temp)
  5. if guess == 8:
  6.     print('卧槽, 你特么是小甲鱼心里的蛔虫么?!')
  7.     print('哼, 猜中了也没有奖励') # 打字的时候起一身鸡皮疙瘩
  8. else:
  9.     print('猜错啦, 小甲鱼现在心理想的是8!')
  10. print('游戏结束, 不玩了不玩了!')
复制代码
输出如下:
  1. ▶ python wordgame_1.py
  2. ---------------我爱鱼C工作室---------------
  3. 不妨猜下小甲鱼现在心理想的是哪个数字: 9
  4. 猜错啦, 小甲鱼现在心理想的是8!
  5. 游戏结束, 不玩了不玩了!
  6. ▶ python wordgame_1.py
  7. ---------------我爱鱼C工作室---------------
  8. 不妨猜下小甲鱼现在心理想的是哪个数字: 8
  9. 卧槽, 你特么是小甲鱼心里的蛔虫么?!
  10. 哼, 猜中了也没有奖励
  11. 游戏结束, 不玩了不玩了!
复制代码
input, int 都是内置函数 (BIF, Built-in Functions), 打印完提示语句之后 temp 存储来自用户的输入 (暂不清楚被存储为什么类型) 那么后面把这个东西转换为整型, 后面经过一个简单的判断流程, 等于提前设定好的8如何如何, 不等于8如何如何.

甲鱼哥最后讲解了 BIF, 罗列下:
  1. >>> dir(__builtins__)
  2. ['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

评分

参与人数 1鱼币 +3 收起 理由
小甲鱼 + 3

查看全部评分

本帖被以下淘专辑推荐:

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-8 15:29

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表