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
bartleby

Concept explainers

bartleby

Videos

Question
Book Icon
Chapter 13, Problem 5PE
Program Plan Intro

Base Conversion

Program plan:

  • Define a function “baseConversion()”.
    • Declare a variable “digit” and initialize.
    • Print the values of “num” and “digit”.
    • Divide the value of “num” with “base”.
    • If the condition “num == 0” is true
      • Return true.
    • Check another condition “num < base”.
      • Assign the value of “num” to “digit”.
      • Set “num” equal to “0”.
    • If the conditions fails
      • Call the function “baseConversion()”.
  • Call the function “baseConversion()”.

Blurred answer
Students have asked these similar questions
please code in python Write a recursive function to add a positive integer b to another number a, add(a, b), where only the unit 1 can be added, For example add(5, 9) will return 14. The pseudocode is: # Base case: if b is 1, you can just return a + 1 # General case: otherwise, return the sum of 1 and what is returned by adding a and b - 1.
Write a function sum_of_digits(a,b), that takes two arguments a and b, computes a to the power of b, then recursively finds the sum of digits until there is only one digit left. You must PRINT all steps of the process as shown in the below example. sum_of_digits(5,3) will PRINT on the screen the following: 5ˆ3 = 125 = 1 + 2 + 5 = 8 sum_of_digits(2,8) will PRINT on the screen the following: 2ˆ8 = 256 = 2 + 5 + 6 = 13 = 1 + 3 = 4
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
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
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
Computational Software for Intelligent System Design; Author: Cadence Design Systems;https://www.youtube.com/watch?v=dLXZ6bM--j0;License: Standard Youtube License