内容正文:
作业 自定义函数与模块
1.导入math模块,现执行s=math.pow(2,5)>=math.pow(5,2),s的值为( )
A.true B.False
C.True D.false
2.有如下程序,执行后,输出结果为5,对应s中的元素是( )
import math
s=[int(3.8),math.floor(4.4),round(4.5),math.ceil(4.2)]
print(max(s))
A.int(3.8) B.math.floor(4.4)
C.round(4.5) D.math.ceil(4.2)
3.导入random模块,现要求随机产生一个[1,10]区间范围内的正整数,其Python表达式为( )
A.random.random()*10
B.random.uniform(1,10)
C.random.randint(1,10)
D.random.choice(range(10))
4.现调用random模块,执行如下程序,输出结果不可能为( )
import random
cl=[2班,3班,4班,5班,8班]
random.shuffle(cl)
for i in cl:
print(i,end= )
A.8班 5班 2班 3班 4班
B.4班 5班 3班 4班 8班
C.4班 8班 5班 3班 2班
D.8班 5班 4班 3班 2班
5.有如下Python 程序段,假设程序运行正常,若选项A 所示图片是原始图片,则推测程序运行结果图片是( )
from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
choicelist,choice=[50,128,188,255],256
for i in choicelist:
if i<choice:
choice=i
fn=tiger02.jpg
img=np.array(Image.open(fn).convert(L))
rows,cols=img.shape #图像尺寸分别赋值
for i in range(rows): #依次取每个像素的坐标
for j in range(cols):
if (img[i,j]<=choice): #像素值小于等于指定值,赋值1,否则为0
img[i,j]=0
else:
img[i,j]=1
plt.figure(”tiger128”) #指定当前绘图对象
plt.imshow(img,cmap=gray) #显示灰度图像
plt.axis(off) #关闭图像坐标
plt.show() #弹出包含了图片的窗口
A. B.
C. D.
6.有如下Python程序段,运行程序,若输入值为6,则输出的结果为( )
def s(x):
if x<=2:
y=x
else:
y=s(x-1)+s(x-2)
return y
a=int(input(”请输入正整数:”))
result=s(a)
print(result)
A.8 B.9
C.13 D.14
7.有Python 的程序代码如下:
def change_c(s):
if ”a”<=s<=”z”:
s=chr(ord(s)-32)
return s
ss=input(”请输入一串英文字母:”)
n=len(ss)
ans=””
for i in range(n):
c=change_c(ss[i])
ans=c+ans#①
print(ans)
现执行该程序,输入“abcDEF”,下列说法中正确的是( )
A.函数change_c()被调用了3 次
B.函数change_c 的功能是将小写字母变成大写字母
C.输出的内容为“ABCDEF”
D.将①所在语句改为“ans+=c”程序功能不变
8.[2023·江山中学高一]有如下Python 程序段:
def days(y,m,d):
md=[31,28,31,30,31,30,31,31,30,31,30,31]
ans=y*365+y∥4-y∥100+y∥400
for i in range(m-1):
ans+=md[i]
if (y%4==0 and y%100!=0 or y%400==0)and m>=3:
ans+=1
ans+=d
return ans
print(days(2023,2,9)-days(2022,11,29))
运行该程序段后,输出的结果是( )
A.71 B.72