进制转化
1 print("enter the new base") 2 new_base=int(input()) 3 print("Enter the number to be converted") 4 decimalNumber=int(input()) 5 quotient=1 6 answer="" 7 list=["A","B","C","D","D","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"] 8 while decimalNumber!=0: 9 quotient=decimalNumber%new_base 10 decimalNumber=decimalNumber//new_base 11 if quotient<10: 12 answer = str(quotient)+ answer 13 elif quotient>10: 14 answer = list[quotient-10] + answer 15 print("The answer is") 16 print(answer)
用列表储存大于10的数,列表够长,多少进制都可以。如果base>10,就从列表中提数。
20212301
图片:



浙公网安备 33010602011771号