I have developed a python code that is comprised of several functions, I want the output from the last function to be an input in the first function and the program should stop when a certain criterion is met!

for example:

[def f1(something1):
      Block of statements
      return something

def f2(something2):
      Another Block of statements
      return something2 ]

What I want is something2 from the second function (f2), to always be input as something1 in the first function (f1) until a stopping criterion is satisfied.

Any help/advice will be appreciated! Thanks.

7 Years
Discussion Span
Last Post by Simplicity.

Functions are not executed until you call them. So, if you want to execute f1 with the output of f2 as argument, you write

result = f1(f2(value))

You should post the whole code, it would be easier to debug.

Edited by Gribouillis: n/a


Another way is to change f1's return something into return f2(something) But that'll only work if f1 MUST call f2 after it's finished. You're probably better off using Gribouillis' way.

Edited by lagspike: emphasis on must


Thank you so much Gribouillis and lagspike. Let me work on your ideas, give you feedback soon.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.