wood burning stoves 2.0*
The moose likes Jython/Python and the fly likes Python Calculator: Several options, changing the number Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Languages » Jython/Python
Bookmark "Python Calculator: Several options, changing the number " Watch "Python Calculator: Several options, changing the number " New topic
Author

Python Calculator: Several options, changing the number

daniel kidanee
Greenhorn

Joined: Feb 23, 2014
Posts: 19
Hello I am new to python and I am trying to do an assignment but I couldn't get the needed output I am supposed to
get. Can any one suggest me what I am missing? Thank you!
Assignment:
The last exercise in this chapter continues with the exercise from the last chapter, the calculator. In this exercise, expand the existing code by implementing the following new features: (A) Calculator does not automatically quit when the result is given, allowing user to do new calculations. The user has to select "6" in the menu to exit the program. (B) The calculator shows the selected numbers in the main menu by printing "Current numbers:" and the user-given input. By selecting "5" in the calculator menu, the user can change the given numbers. When implemented correctly, the program prints out following:
Again, implement the program within one large while True-segment, which is terminated with break if the user selects the option "6".
Example output


Calculator
Give the first number: 100
Give the second number: 25
(1) +
(2) -
(3) *
(4) /
(5)Change numbers
(6)Quit
Current numbers: 100 25
Please select something (1-6): 5
Give the first number: 10
Give the second number: 30
(1) +
(2) -
(3) *
(4) /
(5)Change numbers
(6)Quit
Current numbers: 10 30
Please select something (1-6): 1
The result is: 40
(1) +
(2) -
(3) *
(4) /
(5)Change numbers
(6)Quit
Current numbers: 10 30
Please select something (1-6): 6
Thank you!


My code's output:
Calculator
Give the first number: 100
Give the second number: 25
(1) +
(2) -
(3) *
(4) /
(5)Change numbers
(6)Quit
Current numbers: 100 25
Please select something (1-6): 5
Change numbers
Give the first number: 10
Give the second number: 30
(1) +
(2) -
(3) *
(4) /
(5)Change numbers
(6)Quit
Current numbers: 10 30
Please select something (1-6): 1
The result is: 40
Give the first number: 6
Give the second number:
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4167
    
  21

The problem is that you are asking for the user to enter value1 and value2 when you shouldn't be. I guess the rule is that you should not prompt the user for value1 and value2 if the selection is 1,2,3, or 4. Instead you should just display the choices. This might mean you have to define the selection variable earlier (before the while) so you can check its value when deciding to display the value prompts.


Steve
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Python Calculator: Several options, changing the number
 
Similar Threads
Java Assignment
Map<Integer, Integer> intMap = new Hashtable<Integer, Integer>(); does not work
return value???
problems
Trouble with sorting objects