while True:
for event in pygame.event.get(): #
if event.type==pygame.QUIT: #
sys.exit() #退出程序
if event.type==pygame.MOUSEBUTTONDOWN: #
while True:
for event in pygame.event.get(): #
if event.type==pygame.QUIT: #
sys.exit() #退出程序
if event.type==pygame.MOUSEBUTTONDOWN: #
screen.fill((255,255,0)) #窗口填充黄色*
#加载背景图像
#将背景图画在窗口
pygame.display.update() #窗口刷新
from PIL import Image import numpy as np import matplotlib. pyplot as plt #打开图像并转化成数字矩阵 img-np. array(Image. open("hjpg". convert("L")) #图像尺寸分别赋值 rows, cols=img. shape #调整每个像素的RGB值 for i in range(rows): for j in range(cols): if (img[ij]<=128): img[i, j]=0 else: img[i, j]=1 #生成新的图像并显示 plt. figure("hh") plt. imshow(img. cmap="gray") plt. axis("ff") plt. show( ) |
from PIL import Image import numpy as np import matplotlib. pyplot as plt img-np. array(Imagc. open("hh. jpg")) rows, cols, dims= img. shape for i in range(5000): x=np. random. randint(0, rows) y=np. random. randint(0, cols) img[x, y]=0 plt. figure("hh") pt. imshow(img) pltaxis("off") plt. show( ) |
import math
def pay(w,p):
if w>20:
①
return money
else:
returm 0
weight = int(input("行李重量:"))
price = int(input("机票价格:"))
extra = ②
print("超重量行李费为:"+str(extra))
① ②
import pandas as pd
df1=pd. DataFrame([[10, 20], [30, 40]], columns=['A','B'])
df2=pd. DataFrame([50, 60], [70, 80]], columns=['A',B'])
df=df1. append(df2,ignore_ index= True)
print(df)
该程序段运行后输出结果为( )
import math
def ss(n):
Flag=True
i=2
while i <= int(math.sqrt(n))and Flag:
if
Flag = False
return Flag
n=int(input(“输入一个大于2的偶数”))
for i in rang(2,n//2+1):
if
print(str(n)+"="+str(i)+"+"+str(n-i))
如果输入“8”则结果显示
import math
def IsPrime(i):
if i==1:
return False
for j in range(2,int(math.sqrt(i))+1):
if:
return False
return True
a=int(input("请输入a:"))
b=int(input("请输入b:"))
summ=0
for i in range(a,b+1):
if IsPrime(i):
while t>0:
summ=summ+t%10
print("数字和为:",summ)
1 bmp
1 bmp属性截图 |
#程序段 1: from PIL import Image import numpy as np import matplotlib.pyplot as plt img=np.array(Image.open('1.bmp').convert("L")) rows,cols=img.shape#获取图像的行数和列数 for i in range(rows): for j in range(cols): if img[i,j]>128: img[i,j]=0 #设置为黑色 else: img[i,j]=1 #设置为白色 plt.figure("1.bmp") plt.imshow(img,cmap="gray") #以灰度模式显示 plt.axis("off") plt.show() |
说明:以上程序段1实现将1.bmp 以黑底白字显示
请根据以上信息回答下列问题:
A. rows,cols=img.shape B. for i in range(rows)
C. img[i,j],img[i,cols-j]=img[i,cols-j],img[i,j] D. plt.imshow(img,cmap="gray")
应该修改为:;
#程序段 2: from PIL import Image import numpy as np import matplotlib.pyplot as plt img=np.array(Image.open('1.bmp').convert("L")) rows,cols=img.shape for i in range(rows): for j in range(cols//2): img[i,j],img[i,cols-j]=img[i,cols-j],img[i,j] plt.figure("hh") plt.imshow(img,cmap="gray") plt.axis("off") plt.show() |