MYLAB PROGRAMMING STARTING OUT W/ PYTHO
MYLAB PROGRAMMING STARTING OUT W/ PYTHO
4th Edition
ISBN: 9780134484822
Author: GADDIS
Publisher: PEARSON
bartleby

Concept explainers

Expert Solution & Answer
Book Icon
Chapter 12, Problem 1MC
Program Description Answer

A function which calls itself is called as recursion.

Hence, the correct answer is option “C”.

Expert Solution & Answer
Check Mark

Explanation of Solution

Recursion:

Recursion is a process where function is called again and again by itself for a specific number of times.

  • There are two types of recursive functions. They are as follows:
    • Direct recursion
    • Indirect recursion

Direct recursion:

When a function calls the same function repeatedly until the condition becomes false, then it is called as direct recursion.

Indirect recursion:

When a function calls another function which in turn calls the same calling function, then it is called as indirect recursion.

Example:

Consider the following example; the function “Add()” can be called itself in the same function definition. Hence, it comes under direct recursion.

#Define the Add()function

def Add()

         #Print the message

         print('Example of recursive function!!')

         #Call the Add() function recursively

         Add()

Explanation for wrong options:

A recursive function cannot call the different function.

Hence, option “A” is wrong.

A recursive function cannot halt the program.

Hence, option “B” is wrong.

A recursive function can call more than once in a program.

Hence, option “D” is wrong.

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
Write a recursive function named sumSquares that returns the sum of the squares of the numbers from 0 to num, in which num is a nonnegative int variable. Do not use global variables; use the appropriate parameters. Also write a program to test your function.
Functions like print which perform an action but don’t return a value are called: Select one: a. recursive functions b. built-in functions c. simple functions d. utility functions e. void functions
Write a recursive function called digit_count() that takes a positive integer as a parameter and returns the number of digits in the integer. Hint: The number of digits increases by 1 whenever the input number is divided by 10. Ex: If the input is: 345 the function digit_count() returns and the program outputs: 3 # TODO: Write recursive digit_count() function here. if __name__ == '__main__':    num = int(input())    digit = digit_count(num)    print(digit)

Chapter 12 Solutions

MYLAB PROGRAMMING STARTING OUT W/ PYTHO

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
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr