https://www.acmicpc.net/problem/11720
작성 답안
N = int(input())
sum = 0
list = map(int, input())
for i in list:
sum += i
print(sum)
타 풀이
N = input()
numbers = list(input())
sum = 0
for i in numbers:
sum += int(i)
print(sum)
※ 형 변환
int 형 변환: int(data) # float, bool 변환 가능
float 형 변환: float(data) # int, bool 변환 가능
str 형 변환: str(data) # int, float, bool chr 변환 가능
chr 형 변환: chr(data) # int, bool 변환 가능
bool 형 변환: bool(data) # int, float, str, chr 변환 가능
bool 형 변환 같은 경우 int, float에서 변환할 때는 data가 0인지 여부에 따라, chr, str에서 변환할 때는 값이 있는지 여부에 따라 True, False를 반환한다.
print(bool(10)) # True
print(bool(0)) # False
print(bool("hi")) # True
print(bool("")) # False
'python' 카테고리의 다른 글
[알고리즘] 구간 합 알고리즘 (0) | 2025.03.26 |
---|---|
[백준 1546번] 평균 - python (0) | 2024.11.23 |
[python] 배열과 리스트 (0) | 2024.11.23 |
[백준 2750번] 수 정렬하기 - python (0) | 2024.11.21 |
[Python] 시간 복잡도 표기법 알아보기 (0) | 2024.11.21 |