File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 1+ def base_to_decimal (num ,base ):
2+
3+ return int (num ,base )
4+
5+ def decimal_to_base (a ,base ):
6+
7+ if a == 0 :
8+ return "0"
9+ conv = ""
10+ while a :
11+ r = int (a % base )
12+ if r < 10 :
13+ conv += str (r )
14+ else :
15+ conv += chr (r - 10 + ord ('A' ))
16+ a //= base
17+ return conv [::- 1 ]
18+
19+ def base_to_base (num , initial_base ,final_base ):
20+
21+ decimal_value = base_to_decimal (num ,initial_base )
22+ return decimal_to_base (decimal_value ,final_base )
23+
24+ num = input ("Enter the Number: " )
25+ initial_base = int (input ("Enter the Initial Base: " ))
26+ final_base = int (input ("Enter the Final Base: " ))
27+
28+ converted_number = base_to_base (num ,initial_base ,final_base )
29+ print (f"{ num } in base { initial_base } is { converted_number } in base { final_base } " )
You can’t perform that action at this time.
0 commit comments