开发者

Python learner needs help spotting an error

开发者 https://www.devze.com 2022-12-22 00:56 出处:网络
This piece of code gives a syntax error at the colon of \"eli开发者_如何学Cf process.loop(i, len(list_i) != \'repeat\':\" and I can\'t seem to figure out why.

This piece of code gives a syntax error at the colon of "eli开发者_如何学Cf process.loop(i, len(list_i) != 'repeat':" and I can't seem to figure out why.

class process:
    def loop(v1, v2):
        if v1 < v2 - 1:
            return 'repeat'
    def isel(chr_i, list_i):
        for i in range(len(list_i)):
            if chr_i == list_i[i]:
                return list_i[i]
            elif process.loop(i, len(list_i) != 'repeat':
                return 'error'()

Edit: I am using 3.1.1 by the by.


elif process.loop(i, len(list_i) != 'repeat':

you forgot a closed-paren, ), just before the !=; so the would-be left-hand side of the comparison opens two parentheses but closes only one -- that's the syntax error: "unbalanced parentheses", if you will.


You're missing a parentheses!

Change

elif process.loop(i, len(list_i) != 'repeat':

to

elif process.loop(i, len(list_i)) != 'repeat':

0

精彩评论

暂无评论...
验证码 换一张
取 消