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.

Recommended Answers

All 3 Replies

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.

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.