作者:手机用户2502878113 | 来源:互联网 | 2023-09-17 09:30
一、程序设计的基本方法 程序设计语言
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 &#61; 0 , 1 while ( a&#43; b) <&#61; 1000 : print ( a&#43; b, &#39;&#61;&#39; , a, &#39;&#43;&#39; , b) a, b &#61; b, a&#43; b
绘制五角星
import turtle as t t. color( &#39;red&#39; , &#39;red&#39; ) t. begin_fill( ) for i in range ( 5 ) : t. forward( 200 ) t. right( 144 ) t. end_fill( ) t. done( )
循环一千万次程序计时
import time limit &#61; 1000 * 10000 start &#61; time. pref_counter( ) while True : limit -&#61; 1 if limit <&#61; 0 : break delta &#61; time. pref_counter( ) - startprint ( &#39;程序运行时间&#xff1a;{}&#39; . formate( delta) )
绘制七彩圆圈
import turtle as t colors &#61; [ &#39;red&#39; , &#39;orange&#39; , &#39;yellow&#39; , &#39;green&#39; , &#39;blue&#39; , &#39;cyan&#39; , &#39;purple&#39; ] for i in range ( 7 ) : t. color( colors[ i] ) t. begin_fill( ) t. right( 360 / 7 ) t. circle( 50 ) t. end_fill( ) t. done( )