Question: Question 2: Magic Calculator [100 marks] Programming Language:Python Have you thought about creating your own calculator? You might, but how difficult is it to create

Question 2: Magic Calculator [100 marks]

Programming Language:Python

Have you thought about creating your own calculator? You might, but how difficult is it to create a calculator that includes all functions? Does it need a lot of programming? Well, Windows 10 calculator contains over 35000 lines of code and that should give you an idea. The good news is that in this assignment you will implement a magic calculator, called MagiCal, which familiarize you with the basics of developing such a program. Who knows, you may develop a future version of Windows calculator in a few years :-)!

Magic calculator or MagiCal is not a regular calculator! MagiCal has special features as follows:

It only accept four operators: Addition, Subtractoin, Multiplication and Division.

It only accepts integer numbers between 0 (inclusive) and 100 (inclusive) as input.

MagiCal should know how many operations it will perform. It takes this information from the user displaying the message 'Hi, how many operations do you want MagiCal to perform? '. Lets assume the user-provided number is k. Now, MagiCal asks the user for k times to provide the operator and two integer numbers as described below:

It prints a message 'Select the operator from the list of Addition (1), Subtraction (2), Multiplication (3), Division (4): '. Based on the user-provided input there should be two types of responses from MagiCal:

If the user enters a valid input, 1, 2 3 or 4, then, the user will be asked to enter two numbers as the operands of the provided operator, as described below.

For any invalid output the magic calculator should notify the user with the message 'Invalid input!'.

To take the first integer number MagiCal displays the message 'Enter the first number in the interval of [0,100]: '.

After entering the first number, MagiCal will ask for the second integer number using the message 'Enter the second number in the interval of [0,100]: '.

If one or both of the provided numbers are not in the specified interval MagiCal will show 'Magic calculator can not perform your operation!', and proceeds for the next operation. If there is not any operation remaining, the program terminates.

Finally, if two numbers are in the specified interval MagiCal applies the operator received in the first step and shows the result in the format of 'first_number operator second_number = result'. Note that if the user-provided operator is division and the second number is 0, MagiCal should display the message 'The denominator cannot be 0.'.

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!