python/리스트

중복숫자 금지[2단계]

june__Park 2021. 2. 28. 00:36
# 중복숫자 금지[2단계]
# 1. arr배열에 1~10 사이의 랜덤 숫자 5개를 저장한다.
# 2. 단 중복되는 숫자가 없어야 한다.
import random

nums = [0 for i in range(5)]

i = 0
while i < len(nums):
    r = random.randint(1,10)

    j = 0
    check = 0
    while j < i:
        if nums[j] == r:
            check = 1
            break
        j += 1

    if check == 0:
        nums[i] = r
        i += 1
    else:
        continue

print(nums)