[英]how to check if variables equal each other
我正在尝试检查两个变量是否相等。 如果是这样,我想重置一个变量并更改另一个。 这是我的示例代码:
eq = int(input("\nhow many equations do you have? "))
matrix = [[] for _ in range(eq)]
solution = [[] for _ in range(eq)]
for i in range(eq*eq):
q = 0
x = 0
a = int(input("input the coefficients to your variables in your equation: "))
matrix[x].append(a)
q += 1
if q == eq:
q = 0
print("It's time to move on to the next equation!")
x += 1
问题是if语句。 其他一切正常。
请查看来自user2357112的评论。 我认为您需要像下面那样修改代码:
eq = int(input("\nhow many equations do you have? "))
matrix = [[] for _ in range(eq)]
solution = [[] for _ in range(eq)]
q = 0
x = 0
for i in range(eq*eq):
a = int(input("input the coefficients to your variables in your equation: "))
matrix[x].append(a)
q += 1
if q == eq:
q = 0
print("It's time to move on to the next equation!")
x += 1
问题很可能是第5行的q = 0
。
q
在循环的每个迭代中都设置为0。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.