Python 3 代码运行出错,去帮忙解决一下!
源代码如下:程序代码:
# coding=utf-8 def divisor(a,b): if a==b: return a else: for i in range(max(a,b)/2+1): if a%i==0 and b%i==0: return int(i) def multiple(a,b): c=divisor(a,b) return a*b/c news=[] s=input("请输入你的两个数字,用逗号隔开:") for i in s.split(","): news.append(int(i)) mdivisor=divisor(news[0],news[1]) multiple=multiple(news[0],news[1]) print("最大公约数为:%d,最小公约数为:%d" % (mdivisor,multiple))
运行结果是:
Traceback (most recent call last):
File "C:/Users/PycharmProjects/untitled/线性方程/练习3.py", line 18, in <module>
mdivisor=divisor(news[0],news[1])
File "C:/Users/PycharmProjects/untitled/线性方程/练习3.py", line 8, in divisor
for i in range(max(a,b)/2+1):
TypeError: 'float' object cannot be interpreted as an integer