Skip to content

Novice_3_숫자 두 개를 입력 받아서, 두 수의 공약수를 찾아보자 #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Angela-Park-JE opened this issue Nov 16, 2021 · 1 comment

Comments

@Angela-Park-JE
Copy link
Owner

내가 한 것

input1 = int(input("첫 번째 수를 입력하세요."))
input2 = int(input("두 번째 수를 입력하세요."))
num_list1 = range(1, input1+1)
num_list2 = range(1, input2+1)
d_list1 = []
d_list2 = []
sorted(num_list1)
sorted(num_list2)
for n1 in num_list1:
	d1=input1%n1
	if d1 == 0:
	    d_list1.append(n1)
for n2 in num_list2:
	d2=input2%n2
	if d2 == 0:
	    d_list2.append(n2)

cd_list = []
for n in range(len(d_list1))
    if d_list1[n] == d_list2[n]:
    	cd_list.append(d_list1[n])
print(cd_list)
@Angela-Park-JE
Copy link
Owner Author

Angela-Park-JE commented Nov 16, 2021

조언 받은 것

input1 = int(input("첫 번째 수를 입력하세요."))
input2 = int(input("두 번째 수를 입력하세요."))
d_list1 = []
d_list2 = []
for n1 in range(1, input1+1):
	if input1%n1 == 0:
	    d_list1.append(n1)
for n2 in range(1, input2+1):
	if input2%n2 == 0:
	    d_list2.append(n2)

cd_list = []
for cd1 in d_list1:
    for n in d_list2:
	    if cd1 == n:
	        cd_list.append(cd1)
print(cd_list)
  • 불필요하게 더 쓰지 않고 바로 가져다 써도 된다.
    (헷갈릴까봐 그리고 오류가 무서워서 자꾸 이렇게 하나하나 나누어서 쓴다.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant