build up a Python based base number converter with menu that user can choose. Please also provide
Question:
build up a Python based base number converter with menu that user can choose. Please also provide the algorithm so that I can study it.
The options for the menu should be
- The first option is to generate and display a random number in a user selected base, as well as its base 10 equivalent.
- The second option is to generate and display a random number in a user selected base, and then convert and display that number in a target base, also selected by the user.
- The third option is to ask the user for a numeric input in a user selected base. The user will then select a target base to convert to and the program will display the conversion result.
- The fourth option is to exit the program.
The program must allow the user to continue selecting from the menu until they select the quit option. The program should not fail if the user enters invalid values. See the example below. Note that this problem has many common processes among the choices and is to be solved using functions that implement those common processes.
The following is a list of functions that correspond to most of the common processes, and which will need to be implemented:
- convertNumberToBase10(STRING pNumberString, INTEGER pBase): returns the base 10 integer value of the input string number. Example: convertNumberToBase10('FF', 16) would return INTEGER 255 (This is the intermediate base value from which all other bases can be generated.)
- generateRandomBaseNumber(INTEGER pBase): returns a valid randomly generated number, as a string, in the chosen base.
- getInteger(): returns a valid INTEGER value from the user
- getBaseFromUser(): returns an INTEGER number for the chosen base
- convertToNewBase(INTEGER p10Number, INTEGER pBase): returns a string of digits in the appropriate base.
- getNumberFromUser(INTEGER pBase): returns a string of digits in the appropriate base.
[Output Example] 1) Generate random number in a base of your choice. 2) Generate random number in a base of your choice and convert it to another base also of your choice. 3) Enter a number in a selected base and convert it to a base of your choice. 4) Quit Program Please enter 1, 2, 3, or 4 8 8 is an invalid menu choice. Select from one of the following menu options. 1) Generate random number in a base of your choice. 2) Generate random number in a base of your choice and convert it to another base also of your choice. 3) Enter a number in a selected base and convert it to a base of your choice. 4) Quit Program Please enter 1, 2, 3, or 4 1 What base would you like to use for your new number? Please select a base value from 2 to 36. 1 Please select a base value from 2 to 36. 2 10001010101011 is a randomly generated number in base 2 and is equal to 8875 base 10. Select from one of the following menu options. 1) Generate random number in a base of your choice. 2) Generate random number in a base of your choice and convert it to another base also of your choice. 3) Enter a number in a selected base and convert it to a base of your choice. 4) Quit Program Please enter 1, 2, 3, or 4 2 What base would you like to use for your new number? Please select a base value from 2 to 36. 16 The generated number is BDD base 16. We will convert that number to a new base. What base would you like to use for your new number? Please select a base value from 2 to 36. 99 Please select a base value from 2 to 36. 10 BDD base 16 is equal to 3037 base 10. Select from one of the following menu options. 1) Generate random number in a base of your choice. 2) Generate random number in a base of your choice and convert it to another base also of your choice. 3) Enter a number in a selected base and convert it to a base of your choice. 4) Quit Program Please enter 1, 2, 3, or 4 f f is an invalid menu choice. Select from one of the following menu options. 1) Generate random number in a base of your choice. 2) Generate random number in a base of your choice and convert it to another base also of your choice. 3) Enter a number in a selected base and convert it to a base of your choice. 4) Quit Program Please enter 1, 2, 3, or 4 3 What base would you like to use for your new number? Please select a base value from 2 to 36. 1 Please select a base value from 2 to 36. ue Please select a base value from 2 to 36. 2 Please enter your number as a base 2 number. Your numeric digit choices for your number are 01. 1234 1234 is not a value in base 2. Your numeric digit choices for your number are 01. 1101 You entered the number 1101 base 2. We will convert that number to a new base. What base would you like to use for your new number? Please select a base value from 2 to 36. 16 1101 base 2 is equal to D base 16. Select from one of the following menu options. 1) Generate random number in a base of your choice. 2) Generate random number in a base of your choice and convert it to another base also of your choice. 3) Enter a number in a selected base and convert it to a base of your choice. 4) Quit Program Please enter 1, 2, 3, or 4 4 Thank you for using my base conversion program. Good-bye!!
Financial Management for Decision Makers
ISBN: 978-0138011604
2nd Canadian edition
Authors: Peter Atrill, Paul Hurley