Skip to content

Commit 511db55

Browse files
Merge pull request geekcomputers#336 from jhbiggs/master
Calculator recovers after errors & strengthen comment language.
2 parents 28b25d4 + 4878276 commit 511db55

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

calculator.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def calc(term):
3232
purpose: This function is the actual calculator and the heart of the application
3333
"""
3434

35-
# This part is for reading and converting arithmic terms.
35+
# This part is for reading and converting arithmetic terms.
3636
term = term.replace(' ', '')
3737
term = term.replace('^', '**')
3838
term = term.replace('=', '')
@@ -57,18 +57,15 @@ def calc(term):
5757
# here goes to the error cases.
5858
except ZeroDivisionError:
5959

60-
print("Can't divide by 0")
61-
exit(1) # exit(1) for indicating an error.
60+
print("Can't divide by 0. Please try again.")
6261

6362
except NameError:
6463

65-
print('Invalid input')
66-
exit(1)
64+
print('Invalid input. Please try again')
6765

6866
except AttributeError:
6967

70-
print('Check usage method')
71-
exit(1)
68+
print('Please check usage method and try again.')
7269

7370
return term
7471

@@ -86,11 +83,12 @@ def result(term):
8683
def main():
8784
"""
8885
main-program
89-
purpose: handles the user inputs and prints
90-
some informations onto console.
86+
purpose: handles user input and prints
87+
information to the console.
9188
"""
9289

93-
print("\nScientific Calculator\nEg: sin(rad(90)) + 50% * (sqrt(16)) + round(1.42^2) - 12mod3\nEnter quit to exit")
90+
print("\nScientific Calculator\n\nFor Example: sin(rad(90)) + 50% * (sqrt(16)) + round(1.42^2)"+\
91+
"- 12mod3\n\nEnter quit to exit")
9492

9593
if sys.version_info.major >= 3:
9694
while True:

0 commit comments

Comments
 (0)