练习记录:python
题目:计算两个数字的最大公约数和最小公倍数
s=[0,0]
print("Enter your number: ")
for i in range(2):
try:
s[i]=eval(input())
except:
print('something goes wrong,please enter again! ')
a=s[0]
b=s[1]
# To get the greatest common divisor
while True:
if a==0 or b==0:
if a==0:
com_divisor=b
print('The greatest common divisor: ',b)
if b==0:
com_divisor=a
print('The greatest common divisor: ',a)
break
elif a>b:
a=a%b
else:
b=b%a
# To get the least common multiple
least_multiple=(s[0]*s[1])/com_divisor
print("The least multiple is: ",int(least_multiple))