Answered step by step
Verified Expert Solution
Question
1 Approved Answer
import string d = string.digits + string.ascii _ letters import math def base _ q _ to _ p ( s , q , p
import string
d string.digits string.asciiletters
import math
def baseqtopsqp: # baseqtop method which takes a string, two bases p and q where number stored in string is in base q and we need to convert it to base p
no ints # Converting string to integer
po; # Setting p and decimal to
decimal
whileno: # Running a while loop to convert number from base q to decimal
decimalnointpowqpo
po
no intmathfloorno;
res # Creating a list to store the remainders
while decimal: # Running a while loop to convert number from decimal to base p
res.appendddecimal p # Appending every remainder to list res
decimal decimal p
res.reverse # Reversing the list res
x intjoinres # Converting list to integer
return x # Returning the required base q to base p number
printbaseqtop # Calling baseqtop method here
Step 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