Control Flow
# while loop, dict, type annotation의 사용import randomcount: int = 5# Generate 'n' unique random numbers within a rangeran_nums: list = random.sample(range(10), count)d: dict = {num: 'even/odd' for num in ran_nums}while count > 0: cur_num: int = ran_nums[count-1] if cur_num % 2 == 0 : d[cur_num] = 'even' else: d[cur_num] = 'odd' count -= 1print(d)# 결과{2: 'even', 8: 'even'..
Python
2024. 11. 25. 21:16