2016-05-08 14 views
-1

このコードは、私がこのコードで何を間違って行ったのか分かりません。 Python 2.7を使用してtkinter内でバイナリ検索を実行しようとしているとき。プログラムがうまくいきません。これは、私はエラーがあるtkinter gui python 2.7のバイナリ検索でエラーが発生する012

http://www.pythonschool.net/data-structures-algorithms/binary-search/

に私のプログラムをベースとしたコードです:Tkinterのコールバックトレースバック(最新の呼び出しの最後)での例外:「Cファイル:を\ Python27 \ libに\ libに-TKの\ののTkinter。コール・リターンself.funcでPY」、ライン1536、(*引数)例外TypeError:binarySearch()は正確に2つの引数(0が与えられた)すべての

from Tkinter import * 
import csv 

with open('scoresRecord.csv', 'rb') as f: 

reader = csv.reader(f) 
your_list = list(reader) 

root = Tk() 
root.resizable(0,0) 
root.title("Score Board") 


def binarySearch(myitem,myList): 
found = False 
bottom = 0 
top = len(myList)-1 
while bottom<=top and not found: 
middle = (bottom+top)//2 
if myList[middle]== myitem: 
    found = True 
elif myList[middle] < myitem: 
    bottom = middle + 1 
else: 
    top = middle-1 

return found 




if __name__=="__main__": 
    Scorelist = [row[0] for row in your_list] 
    Dismissallist =[row[1] for row in your_list] # create a list of only the   dismissal 
    Venuelist =[row[2] for row in your_list] # create a list of only the venue 
    item = int(input(entScore.get())) 

    Scorelist = map(int, Scorelist) 
    rowPos = Scorelist.index(item) 
    isitFound = binarySearch(item,Scorelist) 


if isitFound: 
    Score= Scorelist[rowPos] 
    Dismissal= Dismissallist[rowPos] 
    Venue= Venuelist[rowPos] 
else: 
    Score= ("Not Found") 
    Dismissal= ("Not Found") 
    Venue= ("Not Found") 



numScoreLbl.configure(text=Score) 
numDismissal.configure(text=Dismissal) 
outVenue.configure(text=Venue) 


#==========GUI Section==================# 
+0

あなたが実行しているコードと実際に一致するようにインデントを修正するのがよいでしょう。インデントはPythonでは非常に重要です。投稿した内容はまったく動かないでしょう。 –

答えて

0

まず、あなたのリストが発注されていることを確認し、そうでない場合の結果を取ります間違っているかもしれません。

第二に、あなたが方法を.INDEX使用している場合は、そのパフォーマンスを向上させるため、このような何かを行うことができ、が、この

Scorelist = list(map(int, Scorelist))#convert to list 
isitFound = binarySearch(item,Scorelist) 

の操作を行います。それは、二分探索一部を取り出し

try: 
    index = Scorelist.index(item) 
    isitFound = True 
except ValueError: 
    isitFound = False 

とにかく.indexを使用していました。だからこれは良いです。うまくいくといいでしょう:)

+0

Thanx manあなたのbindaas @ankitbindal – user6298707

+0

あなたの問題を解決した場合、私の答えを正しく記入してください –

関連する問題