我有python 2.7.3,我想安装PIL 1.7.
我下载了"PIL-1.1.7.win32-py2.7"并尝试安装它,但它向我显示了一个错误消息,它在注册表中找不到python 2.7.
"需要python版本2.7,这在注册表中找不到".
我仔细检查,我确信我有python 2.7.3.
问题是什么?
我需要检查用户插入的数字是否已经在列,行或"块"中(仍然在最后一部分工作).由于某些原因这些检查不起作用,我不明白为什么?
我在shell中编写了相同的代码,它运行得很好.
我的代码:
def is_valid_move(board,row, column, digit):
if digit in board[row]:
print "Row already contains", digit
return (False)
else:
return (True)
for i in range(9):
if digit in board[i][row]:
print "Colum already contains", digit
return (False)
break
else:
return (True)
board = [[3,7,0,0,5,0,0,0,0],
[0,6,0,0,3,0,2,0,0],
[0,2,9,4,0,0,0,7,8],
[0,0,4,1,7,0,0,8,0],
[0,0,6,3,0,5,9,0,0],
[0,5,0,0,8,4,1,0,0],
[7,1,0,0,0,8,5,6,0],
[0,0,5,0,1,0,0,2,0],
[0,0,0,0,9,0,0,1,3]]
a=is_valid_move(board,1, 2, 9)
print a
Run Code Online (Sandbox Code Playgroud)
输出我得到:
True
Run Code Online (Sandbox Code Playgroud)
任何想法如何检查数字是否已经在框中?
谢谢!
我正在寻找python中的方法来汇总只包含整数的列表.我看到该方法sum()仅适用于列表,但不适用于列表列表.有什么适合我吗?
谢谢
我需要编写一个程序来计算文件中行的len,并将行数> =返回到用户要求的len大小.问题是len()count(\n)和我不能假设在最后一行之后(\n).如何告诉len()在每一行的末尾不计算(\n)?
def count_long_lines(filename, size):
f=open(filename,'r')
count_line=0
for line in f:
if len(line)-1>=size:
count_line +=1
print count_line
f.close()
Run Code Online (Sandbox Code Playgroud) 我需要构建3个功能.第一个是插入排序,第二个是生成0-1之间的随机数列表,第三个需要创建一个randon数列表(使用第二个函数)并对它们进行排序(使用第一个函数).我最终无法改变测试而不是funcs的参数.它说,我遇到了func 3的问题NameError: global name 'my_list' is not defined.其他功能正常,我在第三个错误的地方?*第一个功能不允许返回任何内容.
谢谢!
我的代码:
def insertion_sort(lst):
for i in range(1,len(lst)):
current=lst[i]
j=i-1
while j>=0:
if current < lst[j]:
lst[j+1] = lst[j]
lst[j] = current
j-=1
else:
break
def random_list(n):
import random
my_list=[]
for i in range(n):
my_list.append (random.random ())
return my_list
def sorted_random_list(n):
random_list(n)
insertion_sort(my_list)
### TEST FUNCTION - DON'T CHANGE THIS ####
def test_sorted(lst):
print lst == sorted(lst) and len(lst) > 0
def test_len(lst, length):
print len(lst)==length
def sort_and_test(lst):
lst = …Run Code Online (Sandbox Code Playgroud) 我需要编写一个函数来获取图像并返回镜像(Y坐标永不改变),而不使用PIL中的任何镜像或翻转模块.
我必须自己写.我收到错误信息:
IndexError: image index out of range
Run Code Online (Sandbox Code Playgroud)
我在这里想念的是什么?
谢谢.
from os.path import exists
import tkMessageBox, tkFileDialog
from PIL import Image, ImageTk, ImageFilter
def flip(im):
'''Flips a picutre horizontally, and returns a new image that is a mirror view of the original'''
org=Image.open(im)
new=Image.new("RGB",org.size)
for x in range(org.size[0]):
a=org.size[0]
for y in range(org.size[1]):
pixel=org.getpixel((x,y))
new.putpixel((a,y),pixel)
a-=1
new.save("new.bmp","bmp")
Run Code Online (Sandbox Code Playgroud)