简体   繁体   中英

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. Everything else works fine.

Please see the comment from 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.

q gets set to 0 every iteration of your loop.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM