문제 링크입니다: https://programmers.co.kr/learn/courses/33/lessons/1863
COS Pro 2급 Python 모의고사 - 거스름돈
고객이 구매한 물건들의 가격과 지불 금액이 주어졌을 때, 거스름돈을 얼마나 줘야 하는지 구하려 합니다. 예를 들어 구매한 물건들의 가격이 [2100, 3200, 2100, 800]이라면 총 구매금액은 8200원입니
programmers.co.kr
회사에서 COS Pro 1급을 따면 상금을 준다고 해서 재미로 2급까지 풀어봤습니다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def solution(price, money): | |
sum = 0 | |
for cost in price: | |
sum = sum + cost | |
if money - sum < 0: | |
return -1 | |
return money - sum |

개발환경: Programmers IDE
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'Python > COS Pro 2급 Python 모의고사' 카테고리의 다른 글
[Programmers] k번째로 작은 수 (0) | 2022.05.12 |
---|---|
[Programmers] 이름에 "j" 또는 "k"가 들어가는 사람 (0) | 2022.05.12 |
[Programmers] 알파벳 바꾸기 (0) | 2022.05.12 |
[Programmers] 키가 K보다 큰 사람 (0) | 2022.05.12 |
[Programmers] 개구리 (0) | 2022.05.12 |