Python Programming: An Introduction to Computer Science, 3rd Ed.
3rd Edition
ISBN: 9781590282755
Author: John Zelle
Publisher: Franklin, Beedle & Associates
expand_more
expand_more
format_list_bulleted
Question
Chapter 13, Problem 6PE
Program Plan Intro
Printing digits of a number
- 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”.
- Define “init” function.
- Call the function “BaseConversion()”.
- Call the function “getDigits()”.
- Printing the list.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents 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?
Chapter 13 Solutions
Python Programming: An Introduction to Computer Science, 3rd Ed.
Ch. 13 - Prob. 1TFCh. 13 - Prob. 2TFCh. 13 - Prob. 3TFCh. 13 - Prob. 4TFCh. 13 - Prob. 5TFCh. 13 - Prob. 6TFCh. 13 - Prob. 7TFCh. 13 - Prob. 8TFCh. 13 - Prob. 9TFCh. 13 - Prob. 10TF
Ch. 13 - Prob. 1MCCh. 13 - Prob. 2MCCh. 13 - Prob. 3MCCh. 13 - Prob. 4MCCh. 13 - Prob. 5MCCh. 13 - Prob. 6MCCh. 13 - Prob. 7MCCh. 13 - Prob. 8MCCh. 13 - Prob. 9MCCh. 13 - Prob. 10MCCh. 13 - Prob. 1DCh. 13 - Prob. 2DCh. 13 - Prob. 3DCh. 13 - Prob. 4DCh. 13 - Prob. 5DCh. 13 - Prob. 1PECh. 13 - Prob. 2PECh. 13 - Prob. 3PECh. 13 - Prob. 4PECh. 13 - Prob. 5PECh. 13 - Prob. 6PECh. 13 - Prob. 7PE
Knowledge Booster
Similar questions
- (Program) Write a program that tests the effectiveness of the rand() library function. Start by initializing 10 counters, such as zerocount, onecount, twocount, and so forth, to 0. Then generate a large number of pseudorandom integers between 0 and 9. Each time 0 occurs, increment zerocount; when 1 occurs, increment onecount; and so on. Finally, display the number of 0s, 1s, 2s, and so on that occurred and the percentage of time they occurred.arrow_forwardWrite a recursive function called print_num_pattern() to output the following number pattern. Given a positive integer as input (Ex: 12), subtract another positive integer (Ex: 3) continually until 0 or a negative value is reached, and then continually add the second integer until the first integer is again reached. For coding simplicity, output a space after every integer, including the last. Do not end output with a newline. Ex. If the input is: 12 3 the output is: 12 9 6 3 0 3 6 9 12 # TODO: Write recursive print_num_pattern() function if __name__ == "__main__": num1 = int(input()) num2 = int(input()) print_num_pattern(num1, num2)if (num1<=0): print(num1,end= '')arrow_forwardplease 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.arrow_forward
- Write a recursive function to implement the recursive algorithm (determining the number of ways to select a set of things from a given set of things). Also, write a program to test your function.arrow_forwardWrite a recursive function PrintPattern1 to print pattern that takes two integer arguments n and k. n is the starting number while k is the ending limit.arrow_forwardImplement a recursive C++ function which takes a character (ch) and a positive integer (n) and prints thecharacter ch, n times on the screen. The prototype of your function should be:void printChar (char ch, int n)For example, calling printChar('*',5) should display ***** on screen.Note: There should NOT be any loop in your function.arrow_forward
- Write a recursive function to implement the recursive algorithm (multiplying two positive integers using repeated addition). Also, write a program to test your function.arrow_forwardUsing Java, write a function that calculates the factorial of a number N using recursive and non-recursive methods. Call both methods with multiple numbers and show that the results are the same.arrow_forwardWrite a recursive function that returns the sum of the digits of an integer.int sumOfDigits(int x);arrow_forward
- Consider the recursive procedure which computes the nth Fibonacci number is the one below. procedure Fl (n) //a function which returns the nth Fibonacci number.// if n < 2 then return(n) else return (F2(2,n,1,1)) endif end Fl procedure F2(i,n,x,y) if iarrow_forwardWrite a program that uses a recursive function to convert a number in decimal to base 8 or base 16.arrow_forward: Write a recursive function to multiply two positive integers without usingthe * operator (or / operator). You can use addition, subtraction, and bit shifting, but you shouldminimize the number of those operations.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning