大学计算机基础最新课件第六章
- 格式:pptx
- 大小:7.75 MB
- 文档页数:20
习题一、选择题1.PowerPoint 2010 的功能是(A)。
A. 适宜制作屏幕幻灯片B. 适宜制作各种文档资料C. 适宜进行电子表格计算和框图处理D. 适宜进行数据库处理2.PowerPoint 2010 幻灯片的文件扩展名是(C)。
A. DOCXB. XLSXC. PPTXD. TXT3.下面不属于幻灯片视图的是(D)。
A. 幻灯片视图B. 备注页视图C. 大纲视图D. 页面视图4.(C)视图方式下,显示的是幻灯片的缩略图,适用于对幻灯片进行组织和排序、添加切换功能和设置放映时间。
A. 幻灯片B. 大纲C. 幻灯片浏览D. 备注页5.如果要选择一组连续的幻灯片,可以先单击第一张幻灯片的缩略图,然后(A)。
A. 在按住Shift键的同时,单击最后一张幻灯片的缩略图B. 在按住Ctrl键的同时,单击最后一张幻灯片的缩略图C. 在按住Alt键的同时,单击最后一张幻灯片的缩略图D. 在按住Tab键的同时,单击最后一张幻灯片的缩略图6.如果要为幻灯片设置统一的外观,可通过(A)进行设置。
A. 模板B. 主题C. 设计D. 母版7.进入幻灯片母版的方法是(C)。
A. 在"开始"选项卡下的“幻灯片”组中,在“新建幻灯片”的下拉列表中选择一种版式。
B. 在"设计"选项卡上选择一种主题C. 在"视图"选项卡上单击"幻灯片母版"按钮D. "视图"选项卡上单击"幻灯片浏览视图"按钮8.在PowerPoint 2010中,打开幻灯片后按(C)键,可以启动幻灯片放映。
A. F3B. F4C. F5D. F69. 在启动幻灯片放映后,幻灯片占据了整个屏幕,无法进行窗口的操作,按(D )键可结束幻灯片放映视图状态。
A. ShiftB. CtrlC. AltD. Esc10. 在PowerPoint 2010中,可以为(D)添加动画效果。
第6讲大学计算机基础——Python简介V2import numpy as np import matplotlib.pyplot as plt h, v0, g = 3000, 200, 9.8tmax=np.sqrt(2*h/g)t = np.linspace(0, tmax)xt = v0*t yt = h-1/2*g*t**2plt.plot(xt,yt,'r -')plt.grid('on')plt.axis([0, 5000, 0, h])plt.show()⏹绘制弹道轨迹☐h=3000☐v 0=200问题1:要绘制多条轨迹怎么办?3import numpy as np import matplotlib.pyplot as plt h, v0, g = 3000, 200, 9.8tmax=np.sqrt(2*h/g)t = np.linspace(0, tmax)xt = v0*t yt = h-1/2*g*t**2plt.plot(xt,yt,'r -')plt.grid('on')plt.axis([0, 5000, 0, h])plt.show()⏹绘制炸弹轨迹☐h=3000☐v 0=200问题2:别处要用这段代码怎么办?根据h 和v 0计算x t 和y t4import numpy as npimport matplotlib.pyplot as plth, v0, g = 3000, 200, 9.8tmax=np.sqrt(2*h/g)t = np.linspace(0, tmax)xt = v0*t yt = h-1/2*g*t**2plt.plot(xt,yt,'r -')plt.grid('on')plt.axis([0, 5000, 0, h])plt.show()tmax=np.sqrt(2*h/g)t = np.linspace(0, tmax)xt = v0*t yt = h-1/2*g*t**2根据h 和v 0计算x t 和y t calBombTrace calBombTrace (h, v0)xt, yt=calBombTrace(h, v0)xt, yt=calBombTrace(h, v0)目录2.1 概述2.2 初识Python2.3 分支2.4 循环2.5列表2.6 其它数据类型2.7 函数5函数6def 函数名():语句1……语句n 缩进要相同冒号不能少括号不能少def 表示定义函数函数体命名规则与变量类似尽量反映函数功能例:定义打印当前日期和时间的函数7print ('今天是:', time.strftime('%Y-%m-%d'))print ('现在是:', time.strftime('%H:%M:%S'))print ('今天是:', time.strftime('%Y-%m-%d'))print ('现在是:', time.strftime('%H:%M:%S'))def printTime():import timeprintTime()函数体在调用后才会执行2.7.2 参数传递例:定义函数,功能是打印给定数字,且保留5位小数8print_(x):def print('%.5f'% x)a = print_(x ):print ('%.5f'% x )eval (input ('a='))print_(a )如有多个参数,用逗号隔开参数在函数体内的使用方法与变量相同调用时将具体值赋给参数2.7.2 参数传递定义函数,功能是打印列表L中所有元素的n次方之和9习题def Ln = [x**n for x in L]print(sum(Ln))L = [1, 2, 3, 4, 5]printSumLn(L, n):Ln = [x**n for x in L]print (sum (Ln))n = 3printSumLn(L, n)2.7.2 参数传递定义函数,功能是打印列表L中所有元素的n次方之和,n的默认值为110def printSumLn(L, n):L = [1, 2, 3, 4, 5]printSumLn(L, n=1):Ln = [x**n for x in L]print (sum (Ln))n = 3printSumLn(L, n)#n 为给定值3printSumLn(L)#n 为默认值1任一默认值参数右边不能再出现非默认值参数def f(x=1, y, z=0)def f(x=1,y=1,z=0)def f(y, x=1, z=0)printSumLn(L, n=1):print (sum (Ln))printSumLn(L, n)#n 为给定值3printSumLn(L)#n 为默认值12.7.3 返回值定义函数,功能是计算列表L中所有元素的n次方之和,n的默认值为111def s =calSumLn(L, n=1):Ln = [x**n for x in L]s=sum (Ln)return sL = [1, 2, 3, 4, 5]n = 3y =calSumLn(L, n)print ('y=', y)如有多个返回,用逗号隔开编程计算阴影部分面积139.8, 9.3, 6.4 2.9, 4.1, 4.7 2.0, 1.4, 2.3尽量将需重复使用的代码封装成函数利用函数计算三角形面积=+ + 2S = ( − )( − )( − )三边长输入:三边长a, b, c 输出:三角形面积S编程计算阴影部分面积149.8, 9.3, 6.4 2.9, 4.1, 4.7 2.0, 1.4, 2.3尽量将需重复使用的代码封装成函数利用函数计算三角形面积 = + +2S = ( − )( − )( − )三边长输入:三边长a, b, c 输出:三角形面积S import numpy as np def triArea (a, b, c):p=(a+b+c)/2t=p*(p-a)*(p-b)*(p-c)return np.sqrt(t)S1=triArea (9.8, 9.3, 6.4)S2=triArea (2.9, 4.1, 4.7)S3=triArea (2.0, 1.4, 2.3)print (S1-S2+S3)24.201…15import numpy as npimport matplotlib.pyplot as plt h, v0, g = 3000, 200, 9.8tmax=np.sqrt(2*h/g)t = np.linspace(0, tmax)xt = v0*tyt = h-1/2*g*t**2plt.plot(xt,yt,'r -')plt.grid('on')plt.axis([0, 5000, 0, h])plt.show()⏹绘制炸弹轨迹☐h=3000☐v 0=200根据h 和v 0计算x t 和y timport numpy as np import matplotlib.pyplot as plth, v0, g = 3000, 200, 9.8tmax=np.sqrt(2*h/g)t = np.linspace(0, tmax)xt = v0*tyt = h-1/2*g*t**2plt.plot(xt,yt,'r -')plt.grid('on')plt.axis([0, 5000, 0, h])plt.show()2.7.3 返回值16⏹绘制炸弹轨迹☐h=3000, 2000☐v 0=200, 260根据h 和v 0计算x t 和y t 习题在同一坐标系中绘制各情况下的轨迹for h in H:for v0 in V0:import matplotlib.pyplot as plt import plt.grid('on')numpy as npimport matplotlib.pyplot as pltdef calBombTrace (h, v0):g=9.8; tmax=np.sqrt(2*h/g)t = np.linspace(0, tmax)return v0*t, h-1/2*g*t**2H, V0=[3000, 2000],[200, 260]for h in H:for v0 in V0:xt,yt=calBombTrace(h,v0)plt.plot(xt,yt)plt.grid('on')plt.axis([0, 6500, 0, 3000])plt.show()与数学中函数类似= =1×2×3×⋯×17def f (x):y = 1for i in range (1, x+1):y=y*i return y print (f (10))能不能直观表示这种形式的数学函数?= = 1 −1, =1, >1,( ∈)18if x==1:return 1def else:return x*f(x-1)f (x):if x==1:return 1else :return x*f (x-1)print (f (10))递归调用:自己调用自己1202年,意大利数学家斐波那契提出了“兔子繁殖问题”:假设一对成熟的兔子每月能生一对小兔(一雌一雄),小兔一个月后长为成熟的兔子,假定兔子不会死亡,那么由一对刚出生的小兔开始,第n个月时会有多少对兔子?19/302.7.3 递归函数⏹试写出斐波那契数列第n项的表达式☐1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, …20习题=1 −1+ ( −2), =1,2, ≥32.7.3 递归函数 编程计算斐波那契数列数列的前20项21习题 = 1 −1+ ( −2), =1,2, ≥3def F (n):if n==1 or n==2:return 1else :return F (n-1)+F (n-2)for i in range (1, 21):print (F (i))Fibonacci 函数的递归调用图F(4)返回+F(3)F(2)返回+F(2)F(1)返回返回返回1234516172891103小结函数23def F (n):if n==1 or n==2:return 1else :return F (n-1)+F (n-2)for i in range (1, 21):print (F (i))参数返回值递归调用本章小结⏹第2章☐变量、表达式、赋值等☐分支、循环☐列表等数据结构☐函数☐常用第三方库24import numpy as np import matplotlib.pyplot as plt def calBombTrace (h, v0):g=9.8; tmax=np.sqrt(2*h/g)t = np.linspace(0, tmax)return v0*t, h-1/2*g*t**2H, V0=[3000, 2000],[200, 260]for h in H:for v0 in V0:xt,yt=calBombTrace(h,v0)plt.plot(xt,yt)plt.grid('on')plt.axis([0, 6500, 0, 3000])plt.show()递归经典应用——汉诺塔问题在印度,有一个古老的传说:布拉马圣殿有三根金刚石柱子,第一根柱子上套放了64个金盘,每个金盘都比其下面的金盘略小。