carets Julia Meier calculator #23
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I addressed all but the last 2 optional enhancements.
Calculator
Congratulations! You're submitting your assignment.
Comprehension Questions
1. To address the enhancement that accepts and evaluates one parenthetical statement, I would likely add another block to the "valid_numeric_input" method. This block would check to see if the first and last character entered by the user using the slice method (ex. first_number.slice[-1]), and if true, delete out those characters and evaluate the inside expression. If I wanted to account for the user entering a nested expression (ex. ((3+4) * 5)), my instinct is to first use an array to store the characters in the expression as a separate elements in an array. The array would then identify the number of open and closed bracket sets in total and save that number of sets as a variable. If the number of open brackets was not equal to the number of closed brackets, it would reject the user input. If there were only complete sets, then it would loop through the array (number_of_sets.times) and identify the inner most set of brackets by finding the last "(" and the first ")". It would then evaluate the expression inside the parentheses, and replace the array elements of the expression, including the parentheses, with the resulting answer (7) in the array. It would then continue the times loop.
2. The other optional enhancement is to have the program explicitly return an integer or float. My logic goes that if both inputs are integers or floats with only 1 decimal followed by zero(s), then we know that the resulting answer can be presented as an integer. I would create another method that evaluates the user inputs AND the resulting answer (example: an addition calculation that has the inputs and answer "5.0", "9", "14.0"). The method would evaluate if the answer contains a decimal, and if the decimal is only followed by zeros. If this is true, then it would evaluate each inputs to see if it contains no decimals or a single decimal followed by zero(s).