簡體   English   中英

如何檢查變量是否相等

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM