[HackerRank] Bill Division

Jongmin Lee (SAVZAK)·2021년 6월 5일
0

HackerRank

목록 보기
10/39

[문제 링크]

[입력]

bill: an array of integers representing the cost of each item ordered
k: an integer representing the zero-based index of the item Anna doesn't eat
b: the amount of money that Anna contributed to the bill

[출력]

If Brian did not overcharge Anna, print Bon Appetit on a new line; otherwise, print the difference (i.e., ) that Brian must refund to Anna. This will always be an integer.

[코드]

import math
import os
import random
import re
import sys

#
# Complete the 'bonAppetit' function below.
#
# The function accepts following parameters:
#  1. INTEGER_ARRAY bill
#  2. INTEGER k
#  3. INTEGER b
#

def bonAppetit(bill, k, b):
    # Write your code here
    total = 0
    for i in range(len(bill)):
        if(i!=k):
            total += bill[i]
    
    total = total // 2
    if(total == b):
        print('Bon Appetit')
    else:
        print(abs(total - b))
profile
느리지만 단단하게 걷는 개발자

0개의 댓글