이 프로그램에서 우리는 주어진 숫자의 배수가 존재하는 인덱스 위치를 찾을 것입니다. 이 작업을 위해 Numpy와 Pandas 라이브러리를 모두 사용할 것입니다.
알고리즘
Step 1: Define a Pandas series. Step 2: Input a number n from the user. Step 3: Find the multiples of that number from the series using argwhere() function in the numpy library.
예시 코드
import numpy as np
listnum = np.arange(1,20)
multiples = []
print("NumList:\n",listnum)
n = int(input("Enter the number you want to find multiples of: "))
for num in listnum:
if num % n == 0:
multiples.append(num)
print("Multiples of {} are {}".format(n, multiples)) 출력
NumList: [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19] Enter the number you want to find multiples of: 5 Multiples of 5 are [5, 10, 15]