Sum of Integers - 'int' object is not iterable

前端 未结 5 1177
盖世英雄少女心
盖世英雄少女心 2020-11-30 14:54

My question is related to the sum function in python.

So my code is

def black_jack(a, b):
    if sum(a, b) > 21:
        return 0
    else:
               


        
5条回答
  •  一整个雨季
    2020-11-30 15:18

    sum expects iterable object (like list). So the code should be:

    def black_jack(a, b):
        if sum([a, b]) > 21:
            return 0
        else:
            return sum([a, b])
    
    print black_jack(10, 5)
    

提交回复
热议问题