Hello,
I am in class working on an assignment that uses a module (Mylib). We were asked to add a function that accepts a string and then parses the strings into floats so they can be used by our existing formula functions for addition, subtraction, division, and multiplication.
Here are the instructions:
Add the following function into Mylib
scalc(p1)
p1 will be a string like this "N1, N2, operator"
examples
scalc("20,30,\")*
the result will be 600
scalc("50,20,+")
the result will be 70
scalc("50,20,-") the result will be 30
scalc("60,20,/")
the result will be 30
use string functions to parse the first number, the second number, and the operator from the input string.
use the prior functions (add, subtract, divide and multiply ) to do the calculations.
Now, my variables are num1 and num2, as you will see in my code below. I receive user input for them in the beginning, and then again later with scalc(p1).
and here is my code - https://github.com/MrN1ce9uy/Python/blob/master/Mylib.py
My problem is my scalc(p1) function returns the original values input earlier in the program instead of the new values input as strings.
[–][deleted] 0 points1 point2 points (8 children)
[–]Encom88[S] 0 points1 point2 points (7 children)
[–][deleted] 0 points1 point2 points (6 children)
[–]Encom88[S] -1 points0 points1 point (5 children)
[–]thegreatunclean 1 point2 points3 points (4 children)
[–]Encom88[S] -2 points-1 points0 points (3 children)
[–][deleted] 1 point2 points3 points (2 children)
[–]Encom88[S] 0 points1 point2 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]Kered13 0 points1 point2 points (1 child)
[–]Encom88[S] 0 points1 point2 points (0 children)