It's your Birthday. Your colleagues buy you a cake. The numbers of candles on the cake is provided (x). Please note this is not reality, and your age can be anywhere up to 1,000. Yes, you would look a mess.

As a surprise, your colleagues have arranged for your friend to hide inside the cake and burst out. They pretend this is for your benefit, but likely it is just because they want to see you fall over covered in cake. Sounds fun!

When your friend jumps out of the cake, he/she will knock some of the candles to the floor. If the number of candles that fall is higher than 70% of total candles (x), the carpet will catch fire. 

You will work out the number of candles that will fall from the provided string (y). You must add up the character ASCII code of each even indexed (assume a 0 based indexing) character in y, with the alphabetical position of each odd indexed character in y to give the string a total.

example: 'abc' --> a=97, b=2, c=99 --> y total = 198. 

If the carpet catches fire, return 'Fire!', if not, return 'That was close!'.

Difficulty: introductory

Starter code:

def cake(candles,debris):
	

Solutions:
cake=lambda c,d:['That was close!','Fire!'][c!=0and c*0.7<sum(ord(e)-96*(i%2!=0)for i,e in enumerate(d))]

def cake(candles,debris):
    return 'Fire!' if candles and sum(ord(c) if i%2==0 else ord(c)-96 for i,c in enumerate(debris))>candles*0.7 else 'That was close!'

def cake(candles,debris):
    s = sum(ord(c) if i%2==0 else ord(c)-96 for i,c in enumerate(debris))
    return 'Fire!' if s > 0.7 * candles and candles > 0 else 'That was close!'

def cake(candles,debris):
    res = 0
    for i,v in enumerate(debris):
        if i%2: res+=ord(v)-97
        else: res+=ord(v)
    if res>0.7*candles and candles: return "Fire!"
    else: return 'That was close!'

def cake(candles,debris):
    total = 0
    for i,x in enumerate(list(debris)):
        total += ord(x)-(96 if i%2==1 else 0)
    return 'That was close!' if candles*0.7>total or candles==0 else 'Fire!'


def cake(candles, debris):
    return "Fire!" if 10 * min(candles, (sum(map(ord, debris)) - len(debris)//2*96)) > 7 * candles else "That was close!"

def cake(candles,debris):
    return 'Fire!' if sum(ord(c) - (i % 2 and 96) for i, c in enumerate(debris)) > 0.7 * candles and candles != 0 else 'That was close!'

def cake(candles,debris):
    #your code here
    return 'Fire!' if candles*0.7 < sum([ord(c) if i%2 == 0 else ord(c)-96 for i, c in enumerate(debris)]) and candles != 0 else 'That was close!'

def cake(candles,debris):
    a = ord('a') - 1
    res = sum(ord(x) if i % 2 == 0 else (ord(x) - a) for i, x in enumerate(debris))
    return 'That was close!' if candles == 0 or res / candles <= 0.7 else 'Fire!'

def cake(candles,debris):
    ASCII = {'a': 97, 'b': 98, 'c': 99, 'd': 100, 'e': 101,
             'f': 102, 'g': 103, 'h': 104, 'i': 105, 'j': 106,
             'k': 107, 'l': 108, 'm': 109, 'n': 110, 'o': 111,
             'p': 112, 'q': 113, 'r': 114, 's': 115, 't': 116,
             'u': 117, 'v': 118, 'w': 119, 'x': 120, 'y': 121,
             'z': 122}
    number = {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5,
              'f': 6, 'g': 7, 'h': 8, 'i': 9, 'j': 10,
              'k': 11, 'l': 12, 'm': 13, 'n': 14, 'o': 15,
              'p': 16, 'q': 17, 'r': 18, 's': 19, 't': 20,
              'u': 21, 'v': 22, 'w': 23, 'x': 24, 'y': 25,
              'z': 26}
    chetnie = debris[1::2]
    nechetnie = debris[::2]
    sum_chetnie = 0
    for el in chetnie:
        if el in number:
            sum_chetnie += number[el]
    for el in nechetnie:
        if el in ASCII:
            sum_chetnie += ASCII[el]
    if candles == 0:
        return 'That was close!'
    if sum_chetnie > candles * 0.7:
        return 'Fire!'
    else:
        return 'That was close!'