Question
Python Exercise: Create a Stack class in a file named PB.py. Create a file PB-lab.py and import your Stack class to implement the following exercise.
Python Exercise:
Create a Stack class in a file named PB.py. Create a file PB-lab.py and import your Stack class to implement the following exercise. Test your implementation of the exercise with five (5) test-cases:
Listing 3.1 (Numeric Base Conversion)
Convert the same five decimal integers to the following bases:
a. Base2
b. Base8
c. Base16
Listing 3.1:
from pythonds.basic import Stack
def baseConverter(decNumber, base): digits = "0123456789ABCDEF"
remstack = Stack()
while decNumber > 0: rem = decNumber % base remstack.push(rem) decNumber = decNumber // base
newString = "" while not remstack.isEmpty(): newString = newString + digits[remstack.pop()]
return newString Screenshot of Listing 3.1 for indentation:
from pythonds.basic import Stack def baseConverter (decNumber, base): digits = "0123456789ABCDEF" remstack = Stack() while decNumber > 0: rem = decNumber $ base remstack.push (rem) decNumber = decNumber // base newString = "" while not remstack.isEmpty(): newstring = newString + digits[remstack.pop() ] return newStringStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started