Fill This Form To Receive Instant Help

Help in Homework
trustpilot ratings
google ratings


Homework answers / question archive / CS119 Python Programming PJ 6 – Simple Calculator Please write a Python program that can perform the following 6 mathematical operations for 2 numbers: N1 and N2

CS119 Python Programming PJ 6 – Simple Calculator Please write a Python program that can perform the following 6 mathematical operations for 2 numbers: N1 and N2

Computer Science

CS119 Python Programming

PJ 6 – Simple Calculator

Please write a Python program that can perform the following 6 mathematical operations for 2 numbers: N1 and N2.  You need to prompt the user to enter the first number (of type float), an operator (of type string), and the second number (of type float).  Please see the sample test below to design your application program properly.  This program is a simple calculator for users to play and enjoy.   You must thank the user and stop your program when the operator entered is ‘@’.

 

The 6 valid mathematical operators for this simple 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

            say “The second number cannot be zero!”,  else  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

      say  “The second number cannot be zero!”, else  result = ( N1 % N2 ).

  1. @  for stopping the calculator game.  You must thank the user before leaving this program.  
  2. Otherwise, please say “Sorry,  ____  is not a valid operator!”.    Please show this invalid operator.

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

Optional extension of your program:  You may add another special operator available only in Python.  It is //, which means floor integer division.  For example, 3 // 2 is 1,  but 3 / 2 is 1.5, and 3 % 2 is 1.

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

The output of 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 Simple Calculator of Dr. Simon Lin!   ? must use your name

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

Enter your first number:              10

Enter your operator (@ to stop):   +

Enter your second number:         90

Result:  10.0 + 90.0  =  100.0

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

Enter your first number:              55

Enter your operator (@ to stop):   -

Enter your second number:         49.5

Result:  55.0 - 49.5  =  5.5

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

Enter your first number:              12

Enter your operator (@ to stop):   *

Enter your second number:         55

Result:  12.0 * 55.0  =  660.0

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

Enter your first number:             99

Enter your operator (@ to stop):  /

Enter your second number:         0

The second number cannot be zero!

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

Enter your first number:              99

Enter your operator (@ to stop):   /

Enter your second number:          8

Result:  99.0 / 8.0  =  12.375

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

Enter your first number:                2

Enter your operator (@ to stop): **

Enter your second number:         12

Result:  2.0 ** 12.0  =  4096.0

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

Enter your first number:              99

Enter your operator (@ to stop):  %

Enter your second number:           0

The second number cannot be zero!

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

Enter your first number:              99

Enter your operator (@ to stop):  %

Enter your second number:           8

Result:  99.0 % 8.0  =  3.0

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

Enter your first number:              99

Enter your operator (@ to stop):   \

Enter your second number:           5

Sorry,  \  is not a valid operator!

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

Enter your first number:               0

Enter your operator (@ to stop): @

Enter your second number:          0

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

Thank you for playing this Simple 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 2 items as attachments:

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

       (b) Your WORD document (for example, CS119-PJ6-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 6 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 Case #1:

 

Test Case #2:

 

Test Case #3:

 

pur-new-sol

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE