Fill This Form To Receive Instant Help

Help in Homework
trustpilot ratings
google ratings


Homework answers / question archive / CS119 Python Programming   PJ 7 – Super Calculator Please write a Python program (using modular programming techniques) that can perform the following 6 operators for 2 numbers: N1 and N2

CS119 Python Programming   PJ 7 – Super Calculator Please write a Python program (using modular programming techniques) that can perform the following 6 operators for 2 numbers: N1 and N2

Computer Science

CS119 Python Programming

 

PJ 7 – Super Calculator

Please write a Python program (using modular programming techniques) that can perform the following 6 operators for 2 numbers: N1 and N2.  You need to prompt the user to enter the first number, an operator, and the second number.  Please see the sample test below to design your application program properly.  This program is a super calculator for users to play and enjoy.   You must thank the user and stop your program when the operator (entered by the user) is ‘@’. 

PJ 7 is really an extension of PJ 6 by adding some more user-friendly features.

The 6 valid operators for this super calculator are as follows:

 

  1. +   for addition of  N1 and N2.  Therefore, result = (N1 + N2).
  2.    for subtraction of  N2 from N1.  Therefore, result = (N1 – N2).
  3. *   for multiplication of  N1 with N2.  Therefore, result = (N1 * N2).
  4. /    for floating-point division of N1 by N2.  If N2 is zero, please continue the loop asking user to

      enter a non-zero value for N2 until you receive one.  Then, result = (N1 / N2).

  1. **  for power N2 with base N1 (i.e., N1N2).  Therefore, result =  ( N1 ** N2 ).
  2. %  for division remainder (i.e., modulus) of N1 by N2.  If N2 is zero, please continue the loop

      asking user to enter a non-zero value for N2 until you receive one.  Then, result = ( N1 % N2 ).

  1. @  for stopping the calculator game.  You must thank the user before leaving this program.  
  2. Otherwise, please continue the loop asking user to enter a valid operator until you receive one. Then, apply the operator to N1 and N2 to show the result.

===========================================================================.

Modular Programming Techniques

(1) You must define the following six functions for your main program to call.

  1. Add( N1, N2)              # return N1 + N2
  2. Subtract (N1, N2)       # return N1 - N2
  3. Multiply (N1, N2)       # return N1 * N2
  4. Divide (N1, N2)          # return N1 / N2
  5. Power (N1, N2)          # return N1 ** N2
  6. Modulus (N1, N2)      # return N1 % N2

 

(2) You may define the following functions for your main program or other functions to call.

  1. Check (operator) to check the validity of the operator.
  2. Check (N1, operator, N2) to check the validity of N2.
  3. Evaluate (N1, operator, N2) to apply operator to N1 and N2.

 

(3) In Python, it is very difficult to use global variables. Therefore, N1 and N2 cannot be treated as global variables.

 

(4) In Python, it is almost impossible to pass any parameter by reference or pointer. Therefore, N1 and N2 cannot be passed to any function by reference.  The loop to get a non-zero value for N2 must not be inside the Divide or Modulus functions, otherwise your main program cannot print the non-zero value for N2.

 

===========================================================================.

Your test case #1 must look exactly as follows including the data. You must also do test case #2 and test case #3 with different set of data.  Each of your test case must cover all 6 valid operators (at least once for each) plus an invalid one.  Each test case or test run must begin with a welcome message, and must end with a thank-you message.

 

Welcome to use the Super Calculator of "Dr. Simon Lin"!       ?  must use your name!

1======================================.

Enter your first number:      10

Enter your operator:              +

Enter your second number:  90

Result:  10.0 + 90.0  =  100.0

2======================================.

Enter your first number:       55

Enter your operator:               -

Enter your second number:  49.5

Result:  55.0 - 49.5  =  5.5

3=======================================.

Enter your first number:       12

Enter your operator:               *

Enter your second number:  55

Result:  12.0 * 55.0  =  660.0

4=======================================.

Enter your first number:     99

Enter your operator:             /

Enter your second number: 0

Enter your second number which cannot be zero: 0.0

Enter your second number which cannot be zero: 0.

Enter your second number which cannot be zero:  7

Result: 99.0 / 7.0  =  14.1429

5=======================================.

Enter your first number:     99

Enter your operator:             /

Enter your second number: 8

Result:  99.0 / 8.0  =  12.375

6=======================================.

Enter your first number:       2

Enter your operator:            **

Enter your second number: 12

Result:  2.0 ** 12.0  =  4096.0

7=======================================.

Enter your first number:     99

Enter your operator:            %

Enter your second number:  0

Enter your second number which cannot be zero: 0.

Enter your second number which cannot be zero: 0.00

Enter your second number which cannot be zero:  7

Result: 99.0 % 7.0  =  1.0

8=======================================.

Enter your first number:      99

Enter your operator:             %

Enter your second number:  8

Result:  99.0 % 8.0  =  3.0

9=======================================.

Enter your first number:      99

Enter your operator:               \

Enter your second number:  5

Enter a valid operator:  ^

Enter a valid operator:  ~

Enter a valid operator:  %

Result: 99.0 % 5.0  =  4.0

 

10=========================================.

Enter your first number:      0

Enter your operator:           @

Enter your second number: 0

11=========================================.

Thank you for using this Super Calculator of "Dr. Simon Lin"!      ?  must use your name!

12=========================================.

 

How to submit your Project Assignment (PJ)?

(1) Each program must be well documented with block comments and proper line comments. 

     The beginning of each program must have a block comment to show its author, date, and purpose.

     The following is an example of block comments:

# Author:  _______________   ?  must use your full name here!

# Date:      _________                ?  must put today’s date here!

# Purpose: _______________   ?  must show the purpose of this program here!

(2) You must submit to Canvas the following two items as attachments:

       (a) Your source program (for example, CS119-PJ7.py ), and

       (b) Your WORD document (for example, CS119-PJ7-report .docx ) containing the listing of

             your Python program, and the complete output of your 3 test runs as specified.

      You must not submit a zip file to Canvas.        

=========================================================================.

//You must delete everything above & including this line to make this your Word document to be submitted.

 

 

PJ 7  Report                                  My Name: ______________

 

A. The following is my Python source program:

       // Please copy your source program into here from your Visual Studio IDE.   

       // Your code here must be in color.  You must not show screen prints here.

 

B. The following is the console output of my 3 test runs:

     // One way to copy the console output is to press Ctrl+Alt+PrtScn. 

     // Another way to copy is to use the snipping tool.  To paste the image is to press Ctrl+v.

    // The console display must not be too wide, otherwise it will be too hard to read once pasted.

     // Please make sure your console is long enough to show all your output lines to be captured.

     // Please copy your console output and paste into here:

 

 

Test Run #1:

 

Test Run #2:

 

Test Run #3:

 

 

pur-new-sol

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE