实现进制转化伪代码--20211322肖权城

实现进制转换的伪代码

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=" ")

运行结果

posted @ 2021-11-02 19:56  入林寻梨花白  阅读(12)  评论(0编辑  收藏  举报