Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
එක පැකේජ් එකයි මාසෙටම Unlimited Internet. තාමත් DATA CARD දාන්න සල්ලි වියදම් කරනවද? අඩුම මිලට අපෙන්.
sayuru bandara
Updated:
Tuesday at 12:30 PM
Ad icon
ඉන්ටර්නෙට් එකෙන් හරියටම සල්ලි හොයන්න සහ Success වෙන්න කැමතිද? 🚀 (E-Money & Success Stories)
siri sumana
Updated:
Saturday at 11:44 PM
Gemini AI PRO 18 months Offer
Hawaka
Updated:
May 27, 2026
Ad icon
koko account
DasunEranga
Updated:
May 27, 2026
Ad icon
koko account
DasunEranga
Updated:
May 27, 2026
Electronics
Vehicles
Property
Search
Reply to thread
Forums
Computers & Internet
Problems and Troubleshooting
Coding help
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="dsasa" data-source="post: 29259735" data-attributes="member: 585044"><p>In this assignment you will write a computer program from scratch using the Python programming language. This program will function as a simple calculator.</p><p></p><p><strong>Objectives</strong></p><p></p><ul> <li data-xf-list-type="ul">Write a simple Python program that performs arithmetic operations based on the user input</li> </ul><p><strong>Stage 1: A simple calculator</strong></p><p></p><p>Your calculator should provide the following arithmetic and control operations.</p><ul> <li data-xf-list-type="ul">Arithmetic Operations<ul> <li data-xf-list-type="ul">Addition (+) add(a,b)</li> <li data-xf-list-type="ul">Subtraction (-) subtract(a,b)</li> <li data-xf-list-type="ul">Multiplication (*) multiply(a,b)</li> <li data-xf-list-type="ul">Division (/) divide(a,b)</li> <li data-xf-list-type="ul">Power (^) power(a,b)</li> <li data-xf-list-type="ul">Remainder (%) remainder(a,b)</li> </ul></li> <li data-xf-list-type="ul">Control Operations<ul> <li data-xf-list-type="ul">Terminate (#)</li> <li data-xf-list-type="ul">Reset ($)</li> </ul></li> </ul><p>Write a function select_op(choice) to select the appropriate mathematics function based on the users selection.</p><p>The behavior of the program should be as follows:</p><ul> <li data-xf-list-type="ul">The program should ask the user to specify the desired operation (addition/subtraction/multiplication/division/power/remainder/terminate/reset). <strong>You can start with the code already given in the answer box</strong>. Also, check the example test cases given below.</li> <li data-xf-list-type="ul">Once the user inputs/selects an arithmetic operation, the program should ask the user to enter the two operands one by one, separated by Enter key. If the user made a mistake while entering the parameters, he can return to main menu by pressing ‘$’ key at the end of the input string, followed by the Enter key</li> <li data-xf-list-type="ul">Calculate the result and display the result. Inputs need to be processed as floating point values, even thought the values entered are integers. Example: 2.0 + 4.0 = 6.0</li> <li data-xf-list-type="ul">Return to main menu after displaying the calculation result</li> <li data-xf-list-type="ul">All possible errors (at input or at generation of result) should be handled by the program<ul> <li data-xf-list-type="ul">Examples: </li> </ul></li> </ul> <ul> <li data-xf-list-type="ul">Anything other than a number as operand input</li> <li data-xf-list-type="ul">Anything other than +, -, *, /, ^ and % as arithmetic operators</li> <li data-xf-list-type="ul">Anything other than # and $ as control operators</li> <li data-xf-list-type="ul">Division by zero</li> </ul> <ul> <li data-xf-list-type="ul">The program should keep running until it is stopped by the user (using the terminate command #)</li> </ul><p><strong>Task 1:</strong> Get user input </p><ul> <li data-xf-list-type="ul">Section 1: </li> </ul> <ul> <li data-xf-list-type="ul">Input Arithmetic operation</li> <li data-xf-list-type="ul">Reset or Termination</li> </ul> <ul> <li data-xf-list-type="ul">Section 2: </li> </ul> <ul> <li data-xf-list-type="ul">Input first operand</li> <li data-xf-list-type="ul">Input second operand</li> <li data-xf-list-type="ul">Reset or Termination</li> </ul><p><strong>Task 2:</strong> Implement functions that performs given arithmetic operation on the given operands and produces the result</p><ul> <li data-xf-list-type="ul">Arithmetic operation and the two operands as parameters</li> <li data-xf-list-type="ul">Return the result of the arithmetic operation</li> </ul><p><strong>Task 3:</strong> Call the calculation function by passing user input to select_op(choice) and display the result from within the select_op(choice) function</p><p> Here are some of the messages you might want to display to the users at certain occasions. Copy and paste them as necessary in your code in appropriate situations to help with auto-grading. If there is any differences between the output of your code and the expected output, it will be displayed once you click the "Check" button. You can click on "Show differences" button to highlight the difference between outputs. This will be helpful for you to change your code to match the expected output.</p><p></p><p></p><p>"Enter first number: "</p><p>"Enter second number: "</p><p>"Not a valid number,please enter again"</p><p>"Unrecognized operation"</p><p>"Something Went Wrong"</p><p>Some common issues and solutions are explained in <a href="https://open.uom.lk/mod/forum/discuss.php?d=43814" target="_blank">This Forum Post</a></p><p></p><p></p><p>For example:</p><p></p><table style='width: 100%'><tr><th>Input</th><th>Result</th></tr><tr><td>#</td><td>Select operation.<br /> 1.Add : +<br /> 2.Subtract : -<br /> 3.Multiply : *<br /> 4.Divide : /<br /> 5.Power : ^<br /> 6.Remainder: %<br /> 7.Terminate: #<br /> 8.Reset : $<br /> Enter choice(+,-,*,/,^,%,#,$): #<br /> Done. Terminating</td></tr><tr><td>+<br /> 2<br /> 4<br /> #</td><td>Select operation.<br /> 1.Add : +<br /> 2.Subtract : -<br /> 3.Multiply : *<br /> 4.Divide : /<br /> 5.Power : ^<br /> 6.Remainder: %<br /> 7.Terminate: #<br /> 8.Reset : $<br /> Enter choice(+,-,*,/,^,%,#,$): +<br /> Enter first number: 2<br /> Enter second number: 4<br /> 2.0 + 4.0 = 6.0<br /> Select operation.<br /> 1.Add : +<br /> 2.Subtract : -<br /> 3.Multiply : *<br /> 4.Divide : /<br /> 5.Power : ^<br /> 6.Remainder: %<br /> 7.Terminate: #<br /> 8.Reset : $<br /> Enter choice(+,-,*,/,^,%,#,$): #<br /> Done. Terminating</td></tr><tr><td>/<br /> 5<br /> 0<br /> #</td><td>Select operation.<br /> 1.Add : +<br /> 2.Subtract : -<br /> 3.Multiply : *<br /> 4.Divide : /<br /> 5.Power : ^<br /> 6.Remainder: %<br /> 7.Terminate: #<br /> 8.Reset : $<br /> Enter choice(+,-,*,/,^,%,#,$): /<br /> Enter first number: 5<br /> Enter second number: 0<br /> float division by zero<br /> 5.0 / 0.0 = None<br /> Select operation.<br /> 1.Add : +<br /> 2.Subtract : -<br /> 3.Multiply : *<br /> 4.Divide : /<br /> 5.Power : ^<br /> 6.Remainder: %<br /> 7.Terminate: #<br /> 8.Reset : $<br /> Enter choice(+,-,*,/,^,%,#,$): #<br /> Done. Terminating</td></tr></table><p>Answer<img src="/styles/default/xenforo/smilies/default/sad.gif" class="smilie" loading="lazy" alt=":(" title="Sad :(" data-shortname=":(" />penalty regime: 0 %)</p><p>Ace editor not ready. Perhaps reload page?</p><p>Falling back to raw text area.</p></blockquote><p></p>
[QUOTE="dsasa, post: 29259735, member: 585044"] In this assignment you will write a computer program from scratch using the Python programming language. This program will function as a simple calculator. [B]Objectives[/B] [LIST] [*]Write a simple Python program that performs arithmetic operations based on the user input [/LIST] [B]Stage 1: A simple calculator[/B] Your calculator should provide the following arithmetic and control operations. [LIST] [*]Arithmetic Operations [LIST] [*]Addition (+) add(a,b) [*]Subtraction (-) subtract(a,b) [*]Multiplication (*) multiply(a,b) [*]Division (/) divide(a,b) [*]Power (^) power(a,b) [*]Remainder (%) remainder(a,b) [/LIST] [*]Control Operations [LIST] [*]Terminate (#) [*]Reset ($) [/LIST] [/LIST] Write a function select_op(choice) to select the appropriate mathematics function based on the users selection. The behavior of the program should be as follows: [LIST] [*]The program should ask the user to specify the desired operation (addition/subtraction/multiplication/division/power/remainder/terminate/reset). [B]You can start with the code already given in the answer box[/B]. Also, check the example test cases given below. [*]Once the user inputs/selects an arithmetic operation, the program should ask the user to enter the two operands one by one, separated by Enter key. If the user made a mistake while entering the parameters, he can return to main menu by pressing ‘$’ key at the end of the input string, followed by the Enter key [*]Calculate the result and display the result. Inputs need to be processed as floating point values, even thought the values entered are integers. Example: 2.0 + 4.0 = 6.0 [*]Return to main menu after displaying the calculation result [*]All possible errors (at input or at generation of result) should be handled by the program [LIST] [*]Examples: [/LIST] [/LIST] [LIST] [*]Anything other than a number as operand input [*]Anything other than +, -, *, /, ^ and % as arithmetic operators [*]Anything other than # and $ as control operators [*]Division by zero [/LIST] [LIST] [*]The program should keep running until it is stopped by the user (using the terminate command #) [/LIST] [B]Task 1:[/B] Get user input [LIST] [*]Section 1: [/LIST] [LIST] [*]Input Arithmetic operation [*]Reset or Termination [/LIST] [LIST] [*]Section 2: [/LIST] [LIST] [*]Input first operand [*]Input second operand [*]Reset or Termination [/LIST] [B]Task 2:[/B] Implement functions that performs given arithmetic operation on the given operands and produces the result [LIST] [*]Arithmetic operation and the two operands as parameters [*]Return the result of the arithmetic operation [/LIST] [B]Task 3:[/B] Call the calculation function by passing user input to select_op(choice) and display the result from within the select_op(choice) function Here are some of the messages you might want to display to the users at certain occasions. Copy and paste them as necessary in your code in appropriate situations to help with auto-grading. If there is any differences between the output of your code and the expected output, it will be displayed once you click the "Check" button. You can click on "Show differences" button to highlight the difference between outputs. This will be helpful for you to change your code to match the expected output. "Enter first number: " "Enter second number: " "Not a valid number,please enter again" "Unrecognized operation" "Something Went Wrong" Some common issues and solutions are explained in [URL='https://open.uom.lk/mod/forum/discuss.php?d=43814']This Forum Post[/URL] For example: [TABLE] [TR] [TH]Input[/TH] [TH]Result[/TH] [/TR] [TR] [TD]#[/TD] [TD]Select operation. 1.Add : + 2.Subtract : - 3.Multiply : * 4.Divide : / 5.Power : ^ 6.Remainder: % 7.Terminate: # 8.Reset : $ Enter choice(+,-,*,/,^,%,#,$): # Done. Terminating[/TD] [/TR] [TR] [TD]+ 2 4 #[/TD] [TD]Select operation. 1.Add : + 2.Subtract : - 3.Multiply : * 4.Divide : / 5.Power : ^ 6.Remainder: % 7.Terminate: # 8.Reset : $ Enter choice(+,-,*,/,^,%,#,$): + Enter first number: 2 Enter second number: 4 2.0 + 4.0 = 6.0 Select operation. 1.Add : + 2.Subtract : - 3.Multiply : * 4.Divide : / 5.Power : ^ 6.Remainder: % 7.Terminate: # 8.Reset : $ Enter choice(+,-,*,/,^,%,#,$): # Done. Terminating[/TD] [/TR] [TR] [TD]/ 5 0 #[/TD] [TD]Select operation. 1.Add : + 2.Subtract : - 3.Multiply : * 4.Divide : / 5.Power : ^ 6.Remainder: % 7.Terminate: # 8.Reset : $ Enter choice(+,-,*,/,^,%,#,$): / Enter first number: 5 Enter second number: 0 float division by zero 5.0 / 0.0 = None Select operation. 1.Add : + 2.Subtract : - 3.Multiply : * 4.Divide : / 5.Power : ^ 6.Remainder: % 7.Terminate: # 8.Reset : $ Enter choice(+,-,*,/,^,%,#,$): # Done. Terminating[/TD] [/TR] [/TABLE] Answer:(penalty regime: 0 %) Ace editor not ready. Perhaps reload page? Falling back to raw text area. [/QUOTE]
Insert quotes…
Verification
Payakata winadi keeyak tibeda?
Post reply
Top
Bottom