[TIL] 정글 16일차 - 22/04/12

신승준·2022년 4월 14일
0

TIL

목록 보기
10/34

파이썬 문법

while, else

while문의 조건문을 만족하지 못했을 경우 else문의 코드를 실행시킨다.
백준 - 수 찾기(1920번)

import sys
sys.stdin = open('input.txt')
input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))
a.sort()

m = int(input())
b = list(map(int, input().split()))

for i in b:
    lt = 0
    rt = n - 1
    while lt <= rt:
        mid = (lt + rt)//2
        if a[mid] == i:
            print(1)
            break
        elif a[mid] < i:
            lt = mid + 1
        else:
            rt = mid - 1
    else:
        print(0)

ZeroDivisionError: integer division or modulo by zero

print(1/0)
print(1//0)
print(1%0)

위와 같이 0으로 나누거나 몫을 구할 때, 나머지를 구할 때 해당 에러가 뜨게 된다.

profile
메타몽 닮음 :) email: alohajune22@gmail.com

0개의 댓글