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 6PE
Program Plan Intro

Sum of Numbers

Program Plan:

  • • Define the “main()” function:
    • ○ Initialize the variable “number” as “0”.
    • ○ Check the value of “number”.
      • ■ If it is less than or equal to “0”, then get the input from the user and store it to the variable “number”.
    • ○ Call the function “sumNumbers()” and pass the argument “num”.
    • ○ Display the result on the output screen.
  • • Define the “sumNumbers(num)” function:
    • ○ Check the value of “num”.
      • ■ If it is equal to “0”, then return “num”
      • ■ Otherwise, call the function “sumNumbers()” to recursively perform the addition operation.
  • • 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.
*C Language The greatest common divisor of integers x and y is the largest integer that divides both x and y. Write a recursive function GCD that returns the greatest common divisor of x and y.  The GCD of x and y is defined as follows:  If y is equal to zero, then GCD(x, y) is x; otherwise GCD(x, y) is GCD(y, x % y) where % is the remainder operator.
Computer science C prog Create a recursive function that finds if a number is palindrome or not(return true or false), A palindromic number is a number (such as 16461) that remains the same when its digits are reversed. In the main function asks the user to enter a number then check if it's palindrome or not using the function you created previously.

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++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning