Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A number with a base other than 10 can be written using its base as a subscript. For example, 10112 represents the binary number

A number with a base other than 10 can be written using its base as a subscript. For example, 10112 represents the binary number 1011 which can be converted to a base 10 number as follows: (1 * 20) + (1 * 2) + (0*2) + (1 * 2) = 1+2+0+ 8 = 1110 Similarily, the base 3 number 1123 can be converted to base 10 as follows: (2*30) + (1 * 3) + (1 * 3) = 2 + 3 + 9 = 1410 and the base 8 number 325g can be converted to base 10 as follows: Write a program that reads two numbers from a user. The first input is the number to be converted into base 10, and the second input is the number's base (base of first input). The program determines if the number is a legal number in the given base. if its a legal number the program converts it into a number of a base 10, otherwise it prints the number is not a legal number of a give base. For example the number 3214 is a legal number because 321 is a legal base 4 number. However, since all digits of a base n number must be less than n, the following 3716 is not a legal base 6 number (the digit 7 is not allowed). Note: make sure you solve this question using while or for loop. It is not allowed to use the any external library to convert the input number into a base 10 number. Sample Program runs: Sample run #1 Enter a number: 14732 Base: 6 The input number is not a legal number of a base 6 Sample run #2 Enter a number: 1111 Base: 2 Number in base 10: (1 X 1) + (1 X 2) + (1 X 4) + (1 X 8) = 15 Sample run #3 (5 * 80) + (2*8) + (3*8) = 5 + 16 + 192 = 21310 Enter a number:-1243 Base: 5 Number in base 10: (3 X 1) + (4 X 5) + (2 X 25) + (-1 X 125) = -198 Sample run #4 Enter a number: 147 Base: 8 Number in base 10: (7 X 1) + (4 X 8) + (1 X 64) = 103 Sample run #5 Enter a number:one Error: the input value is not an integer number Sample run #6 Enter a number: 1245 Base: two Error: the input value is not an integer number

Step by Step Solution

3.44 Rating (163 Votes )

There are 3 Steps involved in it

Step: 1

Python code def checknumbase aintnum convert string to integer bintbase conv... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Managerial Economics

Authors: William F. Samuelson, Stephen G. Marks

8th edition

1118808940, 978-1119025900, 1119025907, 978-1119025924, 978-1118808948

More Books

Students also viewed these Computer Engineering questions