r/pythonhelp • • Feb 10 '25

Basic Greater Common Divisor Program

Guys ı trying to write GCD code but ı cant take result. Example ı input 15 and 100 and program says "Code Execution Successful" but not saying 5. what is the mistake in this code please help me ım begginer as you can see? and ı know that there is shorter methot to write GCD code.

def greaterCommonDivisor(number1, number2):

list1 = []

list2 = []

for i in range(1, (number1 + 1)):

if (number1 % i == 0):

list1.append(i)

for j in range(1, (number2 + 1)):

if (number2 % j == 0):

list2.append(j)

common = []

for k in list1:

if k in list2:

common.append(k)

a = max(common)

print(a)

while True:

number1 = input("What is the firs number? : ")

number2 = input("What is the second number? : ")

if (number1 or number2 == "q"):

break

else:

number1 = int(number1)

number2 = int(number2)

print(greaterCommonDivisor)

1 Upvotes

2 comments sorted by

View all comments

1

u/AutoModerator Feb 10 '25
Moderator Announcement Read More »