实现进制转换的伪代码
Write "Enter the new base"
Read newBase
Write "Enter the number to be converted"
Read decimalNumber
Set quotient to 1
WHILE (quotient is not zero)
Set quotient to decimalNumber DIV newBase
Set remainder to decimalNumber REM newBase
Make the remainder the next digit to the left in the answer
Set decimalNumber to quotient
Write "The answer is "
Write answer
python代码
xqc = int(input("进入一个新的base:"))
cym = int(input("进入插入的base:"))
dagongren = 1
a = {10:'A',11:'B',12:'C',13:'D',14:'E',15:'F'}
list2= []
while dagongren != 0:
dagongren = cym//xqc
remainder = cym%xqc
if remainder in a:
remainder = a[remainder]
list2.append(remainder)
cym = dagongren
list2.reverse()
print("The answer is")
for i in list2:
print(i , end=" ")
运行结果