Question: 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
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
