【零基础】Python3学习课后练习题(二)

版权声明:未经授权请勿转载,否则需承担相应法律责任。 https://blog.csdn.net/RonyLance/article/details/82930000

    本文是跟着鱼C论坛小甲鱼零基础学习Python3的视频学习的,课后题也是跟随每一课所附属的题目来做的,根据自己的理解和标准答案记录的笔记。

第二课

测试题:

0.什么是 BIF ?

答:BIF == Built-in Functions (内置函数),是为了方便程序员快速编写脚本程序而诞生的可以随时调用的内置函数。(可用 dir(__builtins__)查看当前版本Python所提供的内置函方法列表)

>>> 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', 'breakpoint', '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']

1.在 Python 看来:‘FishC’ 和 ‘fishc’ 一样吗?

答:不一样, Python 区分大小写,对于 Python 来说大小写不同的两个字符串(或者变量名)是不同的两个个体。

>>> 'FishC' == 'fishc'
False

2.Python 中什么是最重要的?

答:缩进。缩进的存在使得在 Python 中代码高度整洁,而 Python 对缩进的严格要求使得我们在 Python 中使用缩进时要格外注意,如果没有正确使用缩进,得出的代码结果会与我们的期望相去甚远。如果在正确的位置输入冒号 “ : ” ,那么IDLE将会自动在下一行进行缩进。

【Tips: Tab 可为当前光标所在位置添加一个缩进, Ctrl + ] 可以将选择的代码增加一个缩进, Ctrl + [ 可以将选择的代码减少一个缩进】

3. “ == ” 和 “ = ” 分别表示什么?

扫描二维码关注公众号,回复: 3440526 查看本文章

答: “ == ” 是比较符,为判断两边是否相等(相同); “ = ” 是赋值命名符,用于给变量名赋值,或是给值命名变量。

>>> 8 == (5+3)
True


>>> number = 8
>>> number
8

4. “拼接” 是什么?

答:在 Python 使用运算符 “ + ” 的时候,如果两个对象是整型数值或者浮点数,则将其两个对象进行加和;如果两个对象是字符串,则将两个字符串按照前后顺序进行 “拼接” ,这种方法叫做字符串的拼接。

>>> 5 + 8
13
#整型相加
>>> 5.20 + 13.14
18.34
#浮点数相加
>>> '我爱你' + '一生一世'
'我爱你一生一世'
#字符串拼接

动动手:

0. 编写程序:hello.py,要求用户输入姓名并打印“你好,姓名!”

#源代码
name = input('请输入姓名:')
print('你好,'+ name + '!')

#运行结果

================== RESTART: C:/Users/Rony/Desktop/hello.py ==================
请输入姓名:RonyLance
你好,RonyLance!

1.编写程序:calc.py 要求用户输入1到100之间数字并判断,输入符合要求打印“你妹好漂亮”,不符合要求则打印“你大爷好丑”。

#源代码
number = input('请输入1-100任意一个数字:')
num = int(number)
if 1 <= num <= 100:
    print('你妹好漂亮')
else:
    print('你大爷好丑')


#运行结果

=================== RESTART: C:/Users/Rony/Desktop/calc.py ===================
请输入1-100任意一个数字:88
你妹好漂亮
>>> 
=================== RESTART: C:/Users/Rony/Desktop/calc.py ===================
请输入1-100任意一个数字:101
你大爷好丑

猜你喜欢

转载自blog.csdn.net/RonyLance/article/details/82930000