计算机二级python备考笔记(一)

    科技2022-08-26  101

    一、程序设计的基本方法

    程序设计语言

    Python程序的运行方式:交互式,文件式 编程方法:IPO input process output 语言特点:通用,简洁,高产,跨平台,可读,中文 程序设计语言是计算机能够理解和识别用户操作意图的交互体系,按照特定规则组织计算机指令,自动运行。 按照程序设计组织起来的计算机指令成为程序 执行机制:静态语言,脚本语言 静态语言:编译执行,源代码全部编译成目标代码,编译器,速度快,不需要再次编译,同类型平台使用灵活, compiler,C 脚本语言:解释执行,源代码一条条解释成目标代码,解释器,保留源代码,只要有解释器所有平台都能运行,interpreter,Python

    计算机编程

    逻辑思维,实证思维,计算思维 求解问题的过程:①分析问题,抽象交互关系 ②确定方法 ③编写 调试

    Guido 1991 2002 2.x 2008 3.x

    print(‘hello world’)

    斐波那契数列 f(0) = 0 f(1) = 1 f(n) = f(n-1) + f(n-2)

    a, b = 0, 1 while (a+b) <= 1000: print(a+b, '=', a, '+', b) a, b = b, a+b

    绘制五角星

    import turtle as t t.color('red','red') t.begin_fill() for i in range(5): t.forward(200) t.right(144) t.end_fill() t.done()

    循环一千万次程序计时

    import time limit = 1000 * 10000 start = time.pref_counter() while True: limit -= 1 if limit <= 0: break delta = time.pref_counter() - start print('程序运行时间:{}'.formate(delta))

    绘制七彩圆圈

    import turtle as t colors = ['red','orange','yellow','green','blue','cyan','purple'] for i in range(7): t.color(colors[i]) t.begin_fill() t.right(360/7) t.circle(50) t.end_fill() t.done()
    Processed: 0.029, SQL: 9