[英]how to check if variables equal each other
I am trying to check if two variables are equal to each other. 我正在尝试检查两个变量是否相等。 If they are, I want to reset a variable and change another.
如果是这样,我想重置一个变量并更改另一个。 Here is my sample code:
这是我的示例代码:
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
The problem is the if statement. 问题是if语句。 Everything else works fine.
其他一切正常。
Please see the comment from user2357112. 请查看来自user2357112的评论。 I think you need to modify your code like below:-
我认为您需要像下面那样修改代码:
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
The problem is most likely the q = 0
on line 5. 问题很可能是第5行的
q = 0
。
q
gets set to 0 every iteration of your loop. q
在循环的每个迭代中都设置为0。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.