ไม่สามารถเล่นวิดีโอนี้
ขออภัยในความไม่สะดวก

Power of a Number Using Recursion understanding return in recursion || Lesson 35.2 || Python ||

แชร์
ฝัง
  • เผยแพร่เมื่อ 18 ส.ค. 2024
  • #python#learningmonkey#pythoncoding#placements#pythontutorials#pythoncourse#pythonforbeginners#pythonfordatascience#pythonfullcourse#pythonprogramming#pythonfreecourse
    Power of a Number Using Recursion Understanding return in Recursion.
    In this class, we write a program to find the Power of a Number Using Recursion Understanding return in Recursion.
    Power of a Number Using Recursion
    The reader should have prior knowledge of recursive functions execution. Click here.
    Take an example and understand the question better.
    Example:
    Two power five will be 2*2*2*2*2. multiply 2 five times. We get the value 32.
    Two power -5. The output will be 1 / 2 power 5.
    Input: Given base and exponent value.
    Output: Calculate base power exponent value.
    This example will help you understand the return statement in recursive functions.
    Logic
    The function will take the base and exponent values.
    Recursively call the function with a change in exponent value.
    Each recursive function call reduces the exponent value by 1.
    Recursively call the function if the exponent is greater than 0.
    Each time multiple by base value and the value return by the function call.
    Check the below program and analyze the code for better practice.
    Program
    def power(base,exponent):
    if exponent==0:
    return 1
    elif exponent gt 0:
    return base * power(base,exponent-1)
    else:
    return 1/power(base,-exponent)
    base=int(input("enter the number"))
    exponent=int(input("enter power of a number"))
    result=power(base,exponent)
    print(result)
    From the above program, return base * power(base, exponent-1).
    The function has to return the value base* power(base,exponent-1).
    In the above line of code, the return statement is again calling the function.
    The above line execution will take a base value, and it will be multiplied by the value returned by the function power(base,exponent-1).
    Then the value obtained after multiplication with base is returned to the calling function.
    If the exponent is negative, we are returning 1/power(base,-exponent).
    For beginners, A detailed explanation of recursion execution is provided in the video.
    Link for playlists:
    / @learningmonkey
    Link for our website: learningmonkey.in
    Follow us on Facebook @ / learningmonkey
    Follow us on Instagram @ / learningmonkey1
    Follow us on Twitter @ / _learningmonkey
    Mail us @ learningmonkey01@gmail.com

ความคิดเห็น • 23

  • @shivammaurya3319
    @shivammaurya3319 6 หลายเดือนก่อน

    Thanks brother... Literally i search the logic of this problem more than 3- 4 places.. And nobody explain well but you made it clear... Thanks again ❤

    • @LearningMonkey
      @LearningMonkey  6 หลายเดือนก่อน

      Have a great learning in CSE

  • @krishnadamarasingi743
    @krishnadamarasingi743 8 หลายเดือนก่อน

    nice explination.

    • @LearningMonkey
      @LearningMonkey  8 หลายเดือนก่อน

      Thank you
      Have a great learning in CSE

  • @babon_zia
    @babon_zia 3 หลายเดือนก่อน

    wow bro . that's awesome

    • @LearningMonkey
      @LearningMonkey  3 หลายเดือนก่อน

      Have a great learning in CSE

  • @teeheeee7807
    @teeheeee7807 6 หลายเดือนก่อน

    Great sir... thank u so much ❤

    • @LearningMonkey
      @LearningMonkey  6 หลายเดือนก่อน

      Have a great learning in CSE

  • @srimathiv6935
    @srimathiv6935 ปีที่แล้ว +1

    good explanation.....thank you

  • @bhuvanamadhanbhuvanamadhan
    @bhuvanamadhanbhuvanamadhan 4 หลายเดือนก่อน

    Super sir

    • @LearningMonkey
      @LearningMonkey  4 หลายเดือนก่อน

      Have a great learning in CSE

  • @FRUSTRATEÐ_ĐEVELOPER
    @FRUSTRATEÐ_ĐEVELOPER 2 ปีที่แล้ว +1

    Crystal clear bro

  • @srimathiv6935
    @srimathiv6935 ปีที่แล้ว +1

    keep help us...thank you!

  • @gigigirl10
    @gigigirl10 2 ปีที่แล้ว

    Very helpful, thank you!

  • @biswajeetpadhi100
    @biswajeetpadhi100 2 ปีที่แล้ว

    thank you so much

  • @rakeshbabu4790
    @rakeshbabu4790 2 ปีที่แล้ว

    Excellent

  • @Rahul.pal..
    @Rahul.pal.. ปีที่แล้ว

    11^11 not show accurate answer. What can I do. Plz answer me

    • @LearningMonkey
      @LearningMonkey  ปีที่แล้ว +1

      iits working
      def power(base,exponent):
      if exponent==0:
      return 1
      elif exponent >0:
      return base * power(base,exponent-1)
      else:
      return 1/power(base,-exponent)
      base=int(input("enter the number"))
      exponent=int(input("enter power of a number"))
      result=power(base,exponent)
      print(result)

    • @Rahul.pal..
      @Rahul.pal.. ปีที่แล้ว

      @@LearningMonkey thanks 😊 🙏

  • @sayantanbanerjee6277
    @sayantanbanerjee6277 2 ปีที่แล้ว

    in the above program 2^-5 is not run

    • @LearningMonkey
      @LearningMonkey  2 ปีที่แล้ว

      It's working. Post your code once

    • @kalpavrukshg8853
      @kalpavrukshg8853 ปีที่แล้ว

      How will the n in the else part ever reach value 0 we have to add 1 while calling ( - exp +1)
      It looks like infinite loop