-
Notifications
You must be signed in to change notification settings - Fork 14
Test code #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Test code #13
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| def multiply(string): | ||
| arguments = string.split("*") | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. comment |
||
| result = int(arguments[0]) * int(arguments[1]) | ||
| return result | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no blank line at the end of the file |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,75 @@ | ||
| """This module starts the application.""" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How are we going to start the calculator now? |
||
| import calculator_view as calculator_view | ||
| """Module for the CalculationService class""" | ||
| from tkinter import StringVar | ||
| import divide_service as divide_service | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. divide_service does not exist in this repository |
||
| import multiply_service as multiply_service | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the program now does nothing on execution |
||
| calculator_view.initialize_calculator() | ||
| class CalculationService: | ||
| """""Class for keeping track of, and evaluating calculations""""" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. less quotes maybe? |
||
|
|
||
| # Constructor for the class | ||
| # Initializes a String expression and a StringVar equation | ||
| # StringVar is used because it is required for the tkinter text box | ||
| def __init__(self): | ||
| print("initialized") | ||
| self.expression = "" | ||
| self.equation = StringVar() | ||
|
|
||
| def press(self, num): | ||
| """Function to update the expression in the text entry box""" | ||
| # appends the new number to the existing expression | ||
| self.expression = self.expression + str(num) | ||
|
|
||
| # update the expression by using set method | ||
| self.equation.set(self.expression) | ||
|
|
||
| def equalpress(self): | ||
| """Function to evaluate the final expression""" | ||
|
|
||
| # using a try/except in order to catch errors | ||
| try: | ||
|
|
||
| # evaluate the expression/calculation | ||
| if "/" in self.expression: | ||
| total = str(divide_service.divide(self.expression)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. divide_service does not exist in this repository |
||
| if "*" in self.expression: | ||
| total = str(multiply_service.multiply(self.expression)) | ||
| else: | ||
| total = str(eval(self.expression)) | ||
|
|
||
|
|
||
| if float(total) > 10: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not according to Py style guide: "distinguish arguments from the rest" |
||
| total = total + " <:o)" | ||
|
|
||
| self.equation.set(total) | ||
|
|
||
| # reset the expression to the empty string | ||
| self.expression = "" | ||
|
|
||
| # show error on the screen after an exception is caught | ||
| except: | ||
| self.equation.set(" error ") | ||
| self.expression = "" | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unnecessary amount of newlines |
||
|
|
||
|
|
||
| def clear(self): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the code from line 56 onwards not commented intentionally? |
||
| """Function to clear the contents of text entry box""" | ||
| self.expression = "" | ||
| self.equation.set("") | ||
|
|
||
| def get_expression(self): | ||
| """get expression""" | ||
| return self.expression | ||
|
|
||
| def set_expression(self, newExpression): | ||
| """set expression""" | ||
| self.expression = newExpression | ||
|
|
||
| def get_equation(self): | ||
| """get equation""" | ||
| return self.equation | ||
|
|
||
| def set_equation(self, new_equation): | ||
| """set equation""" | ||
| self.equation.set(new_equation) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no blank line at the end of the file |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No comment on function of code