1

I am writing a program and I would like to call twice the same function but with different parameter values.

def finding_numbers(x, y, z):
    """some code here"""
    return z

def one():
    """some code here"""
    return

def try_again(e,t,q):
    p = finding_numbers(x=e,y=t,z=q)
    return p

def main():
    finding_numbers(x,y,z)
    one()
    try_again(e,t,q)

main()

I have tried to call the function as the code above but I don't get the expected return, in fact, it returns nothing. I have tried to create a function with different name def try_again(finding_numbers(x=e,y=t,z=q)) but it does not work. I have also tried to call it from the main again as finding_numbers(x=e,y=t,z=q). I have been ready about how to re-use function within the same python script and I cannot find anything suitable. How to process this?

Ana
  • 131
  • 1
  • 14
  • 2
    You can call another function from the *body* of a function (the part below the first line, that is indented), but not as part of the first line (`def ...`). – mkrieger1 Dec 14 '22 at 13:46
  • There isn't a reproducible issue in the code shown here. There is no problem calling a function this way, and it will `return` normally. However, there is also nothing in the code shown here that would **evidence** a return value from any of the functions. Are you sure you understand [the (non-)relationship between `print` and `return`](https://stackoverflow.com/questions/7129285/)? In order to have a clear question, we would need to see: 1) **complete** code that we can try **without changing anything**; 2) an **exact** explanation of what should observably happen **for that code**. – Karl Knechtel Dec 14 '22 at 21:19
  • @KarlKnechtel. I do understand the very well the difference between print & return. The code has been edited according to the information I had in another answers. The code was just directed on what the title says as I was having lots of problems to do so. – Ana Dec 14 '22 at 23:41
  • 1
    Please read [ask] and take the [tour] and make sure that the post reflects, as accurately as possible, the **question you wanted to ask** (including, as appropriate, a proper [mre]). Please **do not** edit questions to show a solution; that defeats the purpose of Stack Overflow, which is to build a library of clear questions and the answers to those questions. If the problem is already solved at the start, that confuses future readers. – Karl Knechtel Dec 15 '22 at 02:45

2 Answers2

0

you can call the function finding_numbers inside try_again, instead of passing it in as a parameter:

def try_again(e, t, q):
    return finding_numbers(e, t, q)
rae
  • 9
  • 2
0

For your example, your 'try_again' function is not written according to your description.

def try_again(e, t, q):
    q = finding_numbers(x=e, y=t, z=q)
    return q
Kirill Setdekov
  • 329
  • 1
  • 11
  • 1
    Can any of the @administrators explain me how this question has reach youtube? https://www.youtube.com/watch?v=zEXLp1mQu9c – Ana Dec 14 '22 at 15:10