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 program that asks a number “N” from user. Write a function that takes this number “N”, then returns the sum of numbers starting from N to 1. Use this function in your program and show the results. Be careful, your function should be recursive!   I need code on C programming
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.
Computer scientists and mathematicians often use numbering systems other than base 10. Write a program that allows a user to enter a number and a base and then prints out the digits of the number in the new base. Use a recursive function baseConversion (num, base) to print the digits. Hint: Consider base 10. To get the rightmost digit of a base 10 number, simply look at the remainder after dividing by 10. For example, 153 % 10 is 3. To get the remaining digits, you repeat the process on 15, which is just 153 // 10. This same process works for any base. The only problem is that we get the digits in reverse order (right to left). The base case for the recursion occurs when num is less than base and the output is simply num. In the general case, the function (recursively) prints the digits of num // base and then prints num % base. You should put a space between successive outputs, since bases greater than 10 will print out with multi-character "digits." For example, baseConversion(1234,…
Knowledge Booster
Background pattern image
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