Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Nested function problem
#3
(Oct-21-2020, 03:01 PM)deanhystad Wrote: An embedded function still needs to be called. f1() never calls f2() and f2() never calls f3().
I think there is an indentation error. f3() never returns a value. f2() returns c, which is a variable inside f3(). f1() has two returns and will never get to "return a". The code should look more like this:
def f1(x):
    def f2(x):
        def f3(x):
            return math.cos(x)
        return f3(x) * math.sin(x)
    return math.sqrt(f2(x))
Code like this it should always be accompanied by a disclaimer.

"This code is written for the purposes of learning about embedded functions. Any use of this code would be a big mistake."


Thank you! but now what function do I call? to get a result.
Reply


Messages In This Thread
Nested function problem - by chipx - Oct-21-2020, 01:49 PM
RE: Nested function problem - by deanhystad - Oct-21-2020, 03:01 PM
RE: Nested function problem - by chipx - Oct-21-2020, 04:14 PM
RE: Nested function problem - by jefsummers - Oct-21-2020, 05:13 PM
RE: Nested function problem - by chipx - Oct-21-2020, 05:52 PM
RE: Nested function problem - by deanhystad - Oct-21-2020, 06:18 PM
RE: Nested function problem - by chipx - Oct-21-2020, 07:38 PM
RE: Nested function problem - by deanhystad - Oct-21-2020, 08:58 PM
RE: Nested function problem - by jefsummers - Oct-21-2020, 11:56 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  nested function return MHGhonaim 2 729 Oct-02-2023, 09:21 AM
Last Post: deanhystad
  return vs. print in nested function example Mark17 4 1,863 Jan-04-2022, 06:02 PM
Last Post: jefsummers
  Problem with nested JSON Kalet 7 2,934 Dec-09-2021, 11:13 PM
Last Post: Gribouillis
  Exit function from nested function based on user input Turtle 5 3,074 Oct-10-2021, 12:55 AM
Last Post: Turtle
Question Stopping a parent function from a nested function? wallgraffiti 1 3,761 May-02-2021, 12:21 PM
Last Post: Gribouillis
  accessing a second level nested function varsh 3 2,591 Aug-13-2020, 06:57 AM
Last Post: varsh
  How to make this function general to create binary numbers? (many nested for loops) dospina 4 4,584 Jun-24-2020, 04:05 AM
Last Post: deanhystad
  Nested Recursive Function not Returning Etotheitau 2 2,368 May-09-2020, 06:09 PM
Last Post: Etotheitau
  Nested while loop problem + turtle DreamingInsanity 3 3,058 Jul-06-2019, 02:01 PM
Last Post: DreamingInsanity
  Nested for loop strange problem mcva 2 2,697 Mar-16-2019, 12:53 PM
Last Post: mcva

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020