![]() |
2012-12-04
, 01:58
|
|
Posts: 1,338 |
Thanked: 1,055 times |
Joined on Oct 2009
@ California, USA / Jordan
|
#2
|
Traceback (most recent call last):
File "C:/Python23/calculator", line 41, in -toplevel-
a.retry()
File "C:/Python23/calculator", line 37, in retry
sys.exit(0)
SystemExit: 0
import sys class Calculator(object): def calc(self): x = int(input("Please enter the first number: ")) y = int(input("Please enter the second number: ")) #op = Operator op = str.lower(raw_input( "Please enter what method you want to use ((A)ddition, (S)ubtraction, (M)ultiplication, (D)ivision) or type 'end' to quit: ")) if op != "a" and op != "s" and op != "m" and op != "d" and op != "end": exit = str.lower(raw_input("Are you sure you want to exit calculator (Yes or No)? ")) if exit == "yes": sys.exit(0) else: calc() else: if op == "a": print ("\nThe result is: ", x, "+", y, "=", str(x+y)) elif op == "s": print ("\nThe result is: ", x, "-", y, "=", str(x-y)) elif op == "m": print ("\nThe result is: ", x, "*", y, "=", str(x*y)) elif op == "d": print ("\nThe result is: ", x, "/", y, "=", str(float(x)/float(y))) def retry(self): confirm = str.lower(raw_input("Would you like to do another calculation (Yes or No)? ")) b = Calculator() if confirm == "yes": b.calc() else: sys.exit(0) a = Calculator() a.calc() a.retry() raw_input("\nPress any key to exit.")
![]() |
2012-12-04
, 02:03
|
|
Posts: 2,448 |
Thanked: 9,523 times |
Joined on Aug 2010
@ Wigan, UK
|
#3
|
Calculator.calc()
self.calc()
The Following 2 Users Say Thank You to marxian For This Useful Post: | ||
![]() |
2012-12-04
, 06:23
|
|
Posts: 1,338 |
Thanked: 1,055 times |
Joined on Oct 2009
@ California, USA / Jordan
|
#4
|
import sys class Calculator(object): def quit_prompt(self): exit = str.lower(raw_input("Are you sure you want to exit calculator (Yes or No)? ")) if exit == "yes": sys.exit() else: calc() def add(self, x, y): print "The result is: ", x, "+", y, "=", str(x+y) def subt(self, x, y): print "The result is: ", x, "-", y, "=", str(x-y) def mult(self, x, y): print "The result is: ", x, "*", y, "=", str(x*y) def div(self, x, y): print "The result is: ", x, "/", y, "=", str(float(x)/float(y)) def calc(self): x = int(input("Please enter the first number: ")) y = int(input("Please enter the second number: ")) #op = Operator op = str.lower(raw_input( "Please enter what method you want to use ((A)ddition, (S)ubtraction, (M)ultiplication, (D)ivision) or type 'end' to quit: ")) while op != "end": if op == "a": self.add(x, y) if op == "s": self.subt(x, y) if op == "m": self.mult(x, y) if op == "d": self.div(x, y) self.retry() break def retry(self): confirm = str.lower(raw_input("\nWould you like to do another calculation (Yes or No)? ")) if confirm == "yes": self.calc() else: pass a = Calculator() a.calc() print "\nThank you for using the calculator!" raw_input("\nPress any key to exit.")
![]() |
2012-12-16
, 02:39
|
|
Posts: 1,338 |
Thanked: 1,055 times |
Joined on Oct 2009
@ California, USA / Jordan
|
#5
|
The Following User Says Thank You to bandora For This Useful Post: | ||
![]() |
2012-12-16
, 09:38
|
|
Posts: 7,075 |
Thanked: 9,073 times |
Joined on Oct 2009
@ Moon! It's not the East or the West side... it's the Dark Side
|
#7
|
The Following User Says Thank You to Dave999 For This Useful Post: | ||
![]() |
2012-12-16
, 18:11
|
|
Posts: 1,338 |
Thanked: 1,055 times |
Joined on Oct 2009
@ California, USA / Jordan
|
#8
|
So I am taking a basic Python class and one of my assignments was to create a very simple calculator..
Btw, I am using Python 2.3 (As that's what the teacher wants us to use because of livewires)
It's very simple, but I am experiencing an error that I don't know how to fix (which is probably too simple for you guys to fix haha).. So I am getting this error on IDLE:
FarahFa.com
Last edited by bandora; 2012-12-04 at 02:01.