updateMatrix x次数

时间:2013-12-05 20:38:14

标签: python matrix

我正在寻找一种根据用户输入迭代函数x次的方法。

我想过提示用户对我正在更新的特定功能进行多次迭代,然后打印(我在我的Main中调用它),并将该数字存储在变量中。

现在我正在寻找一种实现{while}循环的方法,以便函数迭代直到它达到存储在第一个变量中的数字。

所以基本的想法是这样的:

def main():

  mat = input("What file to read")
  count = input("How many iterations?")
  updateMatrix()

...

def updateMatrix(mat):
  while countmat < count
    ...
      ...
        ...
          countmat = countmat += 1
      print()
main()

这可行吗?

1 个答案:

答案 0 :(得分:0)

很抱歉,如果我不明白你的问题。如果是这样,我会更新/删除它。无论如何,我会尽力回答/澄清这一点。

def main():
  mat = input("What file to read")
  count = input("How many iterations?")
  # you should pass your variables in function to use there
  updateMatrix(mat, count) 


def updateMatrix(mat, count):
    # here you can use mat and count variable as you want
    for in in range(count):
        #this loop will be iterated count times
        # if you want to deal with mat, do it
        print()

main()