标题:Python 3 代码运行出错,去帮忙解决一下!
取消只看楼主
SundyZuo
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2018-12-19
 问题点数:0 回复次数:0 
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
搜索更多相关主题的帖子: Python 运行 出错 for multiple 
2018-12-19 14:51



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-492125-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.028264 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved