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: Python Exercise: Create a Stack class in a file named PB.py. Create

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

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!