Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
4th Edition
ISBN: 9780134444321
Author: Tony Gaddis
Publisher: PEARSON
bartleby

Concept explainers

Question
Book Icon
Chapter 12, Problem 7PE
Program Plan Intro

Recursive Power Method

Program Plan:

  • • Global variable declaration:
    • ○ Initialize the variable “minimum” as “1”.
    • ○ Initialize the variable “maximum” as “100”.
  • • Define the “main()” function:
    • ○ Initialize the variable “number” as “0”.
    • ○ Initialize the variable “exp” as “0”.
    • ○ Get the input from the user and store it to the variable “number”.
    • ○ Check the value of “exp”
      • ■ If it is less than “minimum” or greater than “maximum”, then get the exponent “exp” from the user.
        • ○ Call the function “recursivePower()” and pass the two arguments “number” and “exp”.
        • ○ Display the result on the output screen.
  • • Define the “recursivePower(x, y)” function:
    • ○ Check the value of “y”.
      • ■ If it is equal to “0”, then returns is “1”.
      • ■ Otherwise, call the function “recursivePower()” recursively along with the arguments “x” and the decremented value of “y”.
      • ■ Display the result on the output screen.
  • • Call the “main()” function.

Blurred answer
Students have asked these similar questions
7. Recursive Power Method In Python, design a function that uses recursion to raise a number to a power. The function should accept two arguments: the number to be raised, and the exponent. Assume the exponent is a nonnegative integer.
Recursive Multiplication Design a recursive function that accepts two arguments into the parameters x and y. The function should return the value of x times y. Remember, multiplication can be performed as repeated addition as follows: 7×4=4+4+4+4+4+4+4(To keep the function simple, assume that x and y will always hold positive nonzero integers.)
Recursive Multiplication Design a recursive function that accepts two arguments into the parameters x and y. The function should return the value of x times y. Remember, multiplication can be performed as repeated addition as follows: 7×4=4+4+4+4+4+4+4(To keep the function simple, assume that x and y will always hold positive nonzero integers.) IN Q BASIC LANGUAGE

Chapter 12 Solutions

Starting Out with Python (4th Edition)

Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning