2014-01-21 119 views
0

所以我想拿出一個suduko檢查器代碼。所需數據存儲在外部文件中。我試圖檢查數字是否水平匹配。到目前爲止,我有以下閱讀文件python中的水平線

filename=input("Enter filename:-") 

with open(filename) as f: #opening files 
    content = f.readlines() #obtaining each lines 

for line in lines:    #check each line 
    numbers=line.split() #split each line # split(example 135246 into 1,3,5,2,4,6) 
    newnumber=letter.sort() #arrange to 1,2,3,4,5,6 
    if newnumber=[1,2,3,4,5,6]: 
     print("valid") 
    else: 
     print("not valid") 

我想知道這是否會工作,檢查水平的數字

回答

1
filename=input("Enter filename:-") 

with open(filename) as f: #opening files 
    for line in f: 
     numbers = [int(i) for i in line.strip()] 
     numbers.sort() 
     if numbers == list(range(1,7)): 
      print("valid") 
     else: 
      print("invalid")