Question: This program has to be in PYTHON Write a PYTHON program that will convert a base 10 integer into a different base (base 2 =

This program has to be in PYTHON

Write a PYTHON program that will convert a base 10 integer into a different base (base 2 = binary, base 8 = octal, or base 16 = hexadecimal). Prompt the user for an unsigned integer (i.e. not negative) and display a menu (b or B for binary, o or O for octal, h or H for hexadecimal). Depending on the users choice, do the base conversion and display the result. Continue with this until the user types stop to the prompt for an unsigned integer (the word stop should not be case sensitive).

Question: How do I convert a base 10 integer to base n?

Answer: Divide the number by base n (each time updating the value of the number to be the quotient from

the last division), until you get a quotient of zero. Keep track of the remainders. The remainders collected from bottom up (not top down) will be the answer in base n.

Example:

What is 108 in base 2?

10810 = ?2

108 / 2 = 54 R 0

54 / 2 = 27 R 0

27 / 2 = 13 R 1

13 / 2 = 6 R 1

6 / 2 = 3 R 0

3 / 2 = 1 R 1

1 / 2 = 0 R 1

The answer is 1101100 (notice the answer is not 0011011)

A base 2 number will only have digits 0 and 1. A base 8 number will have digits 0 to 7. A base 16 number

needs digits 0 to 15. Since we dont have a unique symbol for 10 to 15, we use A for 10, B for 11, C for 12,

D for 13, E for 14, and F for 15.

All the logic that does the conversion needs to be written by you. If you use any type of built-in

function/method that is designed to take in a number in one base and return it in another base, you will get

very little to no credit on this assignment.

Use the sample below as a guide for developing your program and for the format of the prompts and the

outputs. Dont add anything extra and create your program to exactly match the specifications given above

and in the sample. Your solution should be divided up into functions. No function should have more than 15

lines of code. The main can be longer, but still should be no more than 40 lines. Comments dont count as

line numbers. In the sample run, the user input is shown in bold so you can easily distinguish input from

program generated text (it does not have to show up as bold in your program).

Sample run

This program will convert a base 10 number into another base

Enter an unsigned integer: hello

Enter an unsigned integer: 5.6

Enter an unsigned integer: 108

B for binary, O for octal, H for hexadecimal: B

1101100

------------------

Enter an unsigned integer: #$%

Enter an unsigned integer: -10

Enter an unsigned integer: 725

B for binary, O for octal, H for hexadecimal: b

1011010101

------------------

Enter an unsigned integer: 825

B for binary, O for octal, H for hexadecimal: hello

Invalid choice!

B for binary, O for octal, H for hexadecimal: 5.6

Invalid choice!

B for binary, O for octal, H for hexadecimal: o

1471

------------------

Enter an unsigned integer: 540

B for binary, O for octal, H for hexadecimal: h

21C

------------------

Enter an unsigned integer: 12345

B for binary, O for octal, H for hexadecimal: H

3039

------------------

Enter an unsigned integer: 703710

B for binary, O for octal, H for hexadecimal: h

ABCDE

------------------

Enter an unsigned integer: -3877

Enter an unsigned integer: 3877

B for binary, O for octal, H for hexadecimal: h

F25

------------------

Enter an unsigned integer: 1000

B for binary, O for octal, H for hexadecimal: O

1750

------------------

Enter an unsigned integer: Stop

Thank you for using this program

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!