728x90
반응형
방법 1 if for문
numbers = []
for i in range(1, 31):
numbers.append(i)
i += 1
def multiple(n):
total = 0
for num in numbers:
if num % n == 0:
total += 1
print(num, end=" ")
print()
print(f"{n}의 배수의 개수는: {total}")
return
n = int(input("배수를 입력하세요: "))
multiple(n)
방법 2 list 내포방법
# 실습 1-1
# list 내포
def count(num):
lists = [i for i in range(1, 31) if i % num == 0]
counts = len(lists)
return lists, counts
num = 3
lists, counts = count(num)
print(f"{num}의 배수: {lists}")
print(f"{num}의 개수: {counts}")
반응형
'하루코딩 > python 하루코딩' 카테고리의 다른 글
| [Pythone] 날짜별 전력 사용량 조회 프로그램 (0) | 2024.11.29 |
|---|---|
| [Pythone] 제품에 따른 출력 부모 자식 클래스 상속 (0) | 2024.11.28 |
| [Python] 날씨 분석 프로그래밍 함수화 (0) | 2024.11.27 |
| [Pythone] 함수 종합 프로그래밍 (날씨데이터 표시) (0) | 2024.11.27 |
| 2025.11.25 자판기 프로그램 연습 코드 (0) | 2024.11.25 |