问题:编写一个程序来求解的线性方程x
,其中ax = b
整数。
给定两个用户输入,a
和b
(a
可能为零),打印:
x
如果存在或如何使用if
elif
andelse
语句解决此问题?到目前为止,这是我的代码:
a = int(input())
b = int(input())
if a == 0 and b == 0:
print("many solutions")
elif b //a == 0:
print(b // a)
elif b//a != 0:
print("no integer solution")
elif a== 0 and b!= 0 or b==0 and a!=0:
print("no solution")
在“ elif”语句中,您给出了:
elif b //a == 0:
print(b // a)
elif b//a != 0:
print("no integer solution")
运算符“ //”用于整数除法,即不保留余数。因此,elif语句将始终执行。
我认为您正在检查其余部分。为此,请使用“%”。这将返回余数
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句