dimanche 3 mars 2019

Invalid syntax issue

there is some issue that I can't understand clearly, I am a beginner, so I constantly missing something but, it is seems to me, it have to work(in very limit of my knowledge), but when I try to assign the "i = random.choice(test)" line give me a syntax error. (also I did found the code from some webpage, modified it for random choice, but clearly I couldn't) Thank you from advance, I will be appreciate.

import random

def binarySearch(alist, item):

    if len(alist) == 0:
        result = False
    else: 
        midpoint = len(alist)//2
        if alist [midpoint]==item:
            result = True
        else:
            if item < alist[midpoint]:
                result = binarySearch(alist[0:midpoint], item)
            else:
                result = binarySearch(alist[midpoint:len(alist)], item)
    return result
test = list(range(0,32)
i = random.choice(test)
print(i)
print(binarySearch(test, i))




Aucun commentaire:

Enregistrer un commentaire