Python Programming: An Introduction to Computer Science, 3rd Ed.
Python Programming: An Introduction to Computer Science, 3rd Ed.
3rd Edition
ISBN: 9781590282755
Author: John Zelle
Publisher: Franklin, Beedle & Associates
Question
Book Icon
Chapter 13, Problem 6PE
Program Plan Intro

Printing digits of a number

Program plan:

  • Define a class “BaseConversion”.
    • Define “init” function.
      • Declaring and initializing instance variables.
    • Define a function “makeList()”.
      • Extract the digits.
      • Append the digit.
      • Divide the value of “num” by “base”.
      • If the condition “self.num < self.base” is true
        • Set the value of “digit”.
        • Set the value of “num” as 0.
        • Append the value of “digit”.
          • If the condition is not true.
          • Call the function “makeList()”.
    • Define a function “getDigits(self)”.
      • Call a function “reverse()”.
      • Define the array of digit strings.
      • Define an array “newlist”.
      • Iterate a “for” loop.
        • Set the value of “num” with array values.
        • Append the value of num.
        • Creating a string “str1”.
  • Call the function “BaseConversion()”.
  • Call the function “getDigits()”.
  • Printing the list.

Blurred answer
Students have asked these similar questions
Write a recursive function that returns true if the digits of a positive integer are in increasing order; otherwise, the function returns false. Also, write a program to test your function.
Write a recursive function, reverseDigits, that takes an integer as a parameter and returns the number with the digits reversed. Also, write a program to test your function.
Write a Recursive Function to print number from Given input down to 0?
Knowledge Booster
Background pattern image
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
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning