李宏毅课程HW0

 1 def wordSum(file):
 2     content = open(file).read()
 3     array = content.split(" ")
 4     orderindex = 0
 5     for i in range(len(array)):
 6         if array.index(array[i]) == i:
 7             print('%s %s %s'% (array[i], orderindex, array.count(array[i])))
 8             orderindex = orderindex + 1
 9 
10 wordSum('words.txt')

Q1:文件的读写?

Q2:split()函数用法 

    参考:https://www.cnblogs.com/huchong/p/7349886.html

Q3:index()函数用法

Q4:print的输出格式

from PIL import Image
import matplotlib.pyplot as plt

img = Image.open('haimian.jpg')
pix = img.load()
width = img.size[0]
print(width)
height = img.size[1]
print(height)
for x in range(width):
    for y in range(height):
        r, g, b = pix[x, y]
        pix[x, y] = int(r/2), int(g/2), int(b/2)
plt.figure('haimian')  # 显示标题
plt.imshow(img, cmap='gray') # 灰度图
plt.axis('off')  # 取消坐标
plt.show()

Q1:import Image的问题?

Q2:操作方法

 

posted @ 2018-09-07 09:53  pororo_dl  阅读(161)  评论(0)    收藏  举报