关于#python#的问题,请各位专家解答!

img

我不知道if后面的条件为什么老显示错误,我认为是对的啊,应该怎么改呢?

题目要求一行输入多个数,要用split分割

a,b,c,d,e,f=input().split(',')
a=float(a)
b=float(b)
c=float(c)
d=float(d)
e=float(e)
f=float(f)
if a*d-b*c==0:
    print('The equation has no solution')
else:
    x=(e*d-b*f)/(a*d-b*c)
    y=(a*f-e*c)/(a*d-b*c)
    print("x=%.1f y=%.1f"%(x,y))

这么写,a,b,c,d,e,f都是字符串,不是整数啊
改成a = int(input())这样子

input()得到的是字符串,你需要用int转成整数再进行计算,修改如下:

a= int(input())
b= int(input())
c= int(input())
d= int(input())
e= int(input())
f= int(input())

您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632