Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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: image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Secrets Of Analytical Leaders Insights From Information Insiders

Authors: Wayne Eckerson

1st Edition

1935504347, 9781935504344

More Books

Students also viewed these Databases questions

Question

Gun shot residue is always visible. True False

Answered: 1 week ago

Question

(2) Who knows about it in the company?

Answered: 1 week ago

Question

(1) What is your current leadership development strategy?

Answered: 1 week ago

Question

(3) How does it influence development activity in the organization?

Answered: 1 week ago