? How to convert?
• Use quotient & remainder
?Divide the quotient by the radix base number until the quotient is 0
• Write remainders in reverse order
17 R4
8140
E.g. octal equivalent of decimal number 140 is 214
2R1
817
? Define two conversion functions
• Use a list variable (converted_number=0)
?Print the list to a string use join() function
def deci_to_any_list (n, radix):
• Use a string variable (converted_number = "")
def deci_to_any_string (n, radix):
0 R2
82
• User inputs
Number-positive number
Radix-between 2 and 16
Output
• Just digits, no gap or another characters
?123 (0) '1' 2' '3' (X)
• "Wrong input!!" if inputs are not in range
• You must use the formatting operator % (TAs will check!!)
>>> [evaluate dec_to_any.py]
Enter a number: 10
Enter a radix: 2
10 in base 10 is 1010 in base 2
>>> [evaluate dec_to_any.py]
Enter a number: 61
Enter a radix: 16
61 in base 10 is 30 in base 16
>>> [evaluate dec_to_any.py]
Enter a number: 5
Enter a radix: 17
Wrong Input!!
>>> [evaluate dec_to_any.py]
Enter a number: -5
Wrong Input!!!