零基础入门学习Python(2)--用Python设计第一个游戏
2018-01-30 14:32
721 查看
前言
小甲鱼的Python课程都是围绕着一个个小游戏,进行
Python的讲解,由易入难。
小游戏流程图
Created with Raphaël 2.1.2Startprint('------------------我爱鱼C工作室------------------')temp = input("不妨猜一下小甲鱼现在心里想的是哪个数字:")guess = int(temp)if guess == 8 print("我草,你是小甲鱼心里的蛔虫吗?!")print("哼,猜中了也没有奖励!")print("游戏结束,不玩啦^_^")Endprint("猜错啦,小甲鱼现在心里想的是8!")yesno小游戏代码
print('------------------我爱鱼C工作室------------------') temp = input("不妨猜一下小甲鱼现在心里想的是哪个数字:") guess = int(temp) if guess == 8: print("我草,你是小甲鱼心里的蛔虫吗?!") print("哼,猜中了也没有奖励!") else: print("猜错拉,小甲鱼现在心里想的是8!") print("游戏结束,不玩啦^_^")
知识点
什么是BIF?
BIF就是 Built-in functions,内置函数。为了方便程序员快速编写脚本程序,python提供了非常丰富的内置函数,我们只需要直接调用即可,例如
print()的功能就是打印到屏幕,
input()的作用就是接收用户输入
Python3提供了多少个
BIF?
在IDLE中,输入
dir(__builtins__),可以看到Python提供的内置方法列表,其中小写的就是BIF。如果想具体查看某个BIF功能,比如
input(),可以在IDLE中输入
help(input)
>>> 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', 'WindowsError', '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 b6c0 ', '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'] >>> help(input) Help on built-in function input in module builtins: input(prompt=None, /) Read a string from standard input. The trailing newline is stripped. The prompt string, if given, is printed to standard output without a trailing newline before reading input. If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise EOFError. On *nix systems, readline is used if available.
‘FishC’ 和 ‘fishc’ 一样吗?
不一样。可以在IDLE中输入
'FishC' == 'fishc',进行测试
>>> 'FishC' == 'fishc' False
Python中什么是最重要的?你赞同吗?
缩进!缩进是Python语言的灵魂,缩进使得python的代码更加精简,并且有层次。在python中对待缩进要十分小心的,因为如果没有使用正确的使用缩进,代码所做的事情就会和你所期望的相去甚远
如果在正确的位置输入
:,IDLE会自动将下一行缩进!
上述例子中出现了
=和
==,都表示什么含义?
==:表示判断是否相等
=:表示赋值,把右边的值给到左边的变量里面去
你听说过
拼接这个词吗?
在一些编程语言,我们可以将两个字符串”相加”在一起,如:
'I' +'Love' +'FishC'会得到
'ILoveFishC',在python里,这种做法叫做拼接字符串。
编写程序:hello.py,要求用户输入姓名打印
你好,xx!
name = input("请输入您的姓名:") print('你好,'+name+'!')
编写程序:calc.py要求用户输入1到100之间的数字并判断,输入符合要求打印
你妹好漂亮^_^,不符合要求打印
你大爷好丑T_T
temp = input("请输入1到100之间的数字:") num = int(temp) if 1 <= num <= 100: print('你妹好漂亮^_^') else: print('你大爷好丑T_T')
相关文章推荐
- 【零基础入门学习Python笔记002】用Python设计第一个游戏:课后测试集答案
- 零基础入门学习Python(2)--用Python设计第一个游戏
- 用Python设计第一个游戏 - 零基础入门学习Python002
- 【零基础入门学习Python笔记004】改进第一次设计的游戏
- Python学习入门基础教程(learning Python)--2 Python简单函数设计 .
- 第002讲:用Python设计第一个游戏 ---学习笔记
- Python学习入门基础教程(learning Python)--2.3.1 Python传参函数设计
- Python学习入门基础教程(learning Python)--2.3 Python自定义函数传参函数设计
- Python学习入门基础教程(learning Python)--2.3.1 Python传参函数设计
- 界面设计01 - 零基础入门学习Delphi42
- Python学习入门基础教程(learning Python)--3.3.1 Python下的布尔表达式
- Python学习入门基础教程(learning Python)--5.2 Python读文件基础
- Python学习入门基础教程(learning Python)--2.2 Python下的变量基础
- 界面设计01 - 零基础入门学习Delphi42
- Python学习入门基础教程(learning Python)--5.1 Python下文件处理基本过程
- Python学习入门基础教程(learning Python)--2.3.3Python函数型参详解
- Python学习入门基础教程(learning Python)--3.3.2 Python的关系运算
- Python学习入门基础教程(learning Python)--3.3.3 Python逻辑关系表达式
- Python初学者(零基础学习Python、Python入门)常见问题:书籍推荐、资料、社区
- Python学习入门笔记-基础知识