Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python Help! I have no idea how to code this problem and I will appreciate if you guys can solve this. Problem statement For this

Python Help!

I have no idea how to code this problem and I will appreciate if you guys can solve this.

Problem statement

For this program, you are to design and implement a calculator for positive integers that uses John Napier's location arithmetic (explained below). The user of your program will enter two numbers, using Napier's notation, and an arithmetic operator. You program is to translate these numerals into Hindu- Arabic decimal numbers, display them, perform desired operations, and finally print the result - in both abbreviated Napier's notation and in Hindu-Arabic decimal notation. The arithmetic operators that your program should recognize are +, -, *, and /. These operators are used to perform Python operations of integer addition, subtraction, multiplication, and division. The program is to be repeated as many times as the user wishes.

You may not use Python constructs that have not been discussed in class so far.

Input

An input to your program will be interactive. Napier used letters to represent successive powers of 2, where a = 20, b = 21, c = 22, d = 23, ... z = 225. When converting to a decimal numeral you simply add the digits:

abdgkl=20 +21 +23 +24 +26 +210 +211 =1+2+8+64+1024+2048=3147 His location numerals used sign-value notation, in which a number is simply the sum of its digits, where order does not matter, and digits can be repeated, e.g. abc = cba = bca abbc = acc = ad

After each number or an operator is entered, you are to make sure that no illegal characters or arithmetic operators were entered. For numbers, an illegal character is anything that is not a letter. For operators, an illegal character is anything other than one of the four operator characters listed above. When an invalid input occurs, the program is not to crash or exit, but to ask the user for the given value again until the valid values are entered.

Output

In addition to printing the decimal values of the two numbers entered by the user, you need to print the result of the operation in both notations. When printing in Napier's notation, make sure you do not repeat letters where a single letter would do, e.g. instead of abbc, you should print ad. In addition, if the result of your calculation is a 0, the equivalent string would be an empty string which we will not be able to see on the screen, so in such a case print a set of quotes, e.g. "". If the result of your calculations is a negative number, print the number with a minus sign in front, e.g. abc.

To represent a given decimal number as a location numeral, express it as a sum of powers of two and then replace each power of two by its corresponding digit (letter). For example, when converting from a decimal number:

87=1+2+4+16+64=20 +21 +22 +24 +26 =abceg You may find standard algorithms for converting from decimal to binary useful to achieve this purpose. To convert from a base-10 integer to its base-2 (binary) equivalent, the number is divided by two, and the remainder serves as the least-significant bit. The (integer) result is again divided by two, its remainder is the next least significant bit. This process repeats until the quotient becomes zero. Example:

13 / 2 = 6 R 1 6/2=3R0 3/2=1R1 1/2=0R1

So 13 in decimal is 1101 in binary which basically tells you to look at letters corresponding to where 1s occurred in the bit stream, which in this case means positions 0, 2, and 3 = acd

Sample run

Enter Napier's number: -ab2 Something is wrong. Try again. Enter Napier's number: abc The first number is: 7 
Enter Napier's number: he lo Something is wrong. Try again. Enter Napier's number: hello The second number is 20,624 Enter the desired arithmetic operation: # Something is wrong. Try again. 

Enter the desired arithmetic operation: - The result is -20,617 or -adhmo Do you want to repeat the program? Enter y for yes, n for no:

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Intranet And Web Databases For Dummies

Authors: Paul Litwin

1st Edition

0764502212, 9780764502217

More Books

Students also viewed these Databases questions