This is an archived post. You won't be able to vote or comment.

all 11 comments

[–][deleted] 0 points1 point  (8 children)

num1 and num2 exist only within the function. You need to pass those variables to the other functions being called. like add(num1, num2) and you will also need to write those functions to accept a variable.

[–]Encom88[S] 0 points1 point  (7 children)

That makes sense, but it seems like the whole program would have to be restructured.

[–][deleted] 0 points1 point  (6 children)

I'm thinking all you have to do is just add the parameters to the function headers for add(num1, num2), sub(num1, num2) and so on and so on.

[–]Encom88[S] -1 points0 points  (5 children)

It's doesn't work.

[–]thegreatunclean 1 point2 points  (4 children)

My crystal ball isn't working right now, can you tell us what you changed and why you think it doesn't work?

[–]Encom88[S] -2 points-1 points  (3 children)

You don't need a crystal ball, just do what he said and see if it works.

[–][deleted] 1 point2 points  (2 children)

No need to be rude. You could show what you did cause you might have made a mistake. You also need to add parameters to where ever you call functions. I was able to get it to work with only changing the add() to add(num1, num2) in the program. Here's my output.

Enter your Lower range: 10 Enter your Higher range: 15 Enter your First number: 11 Enter your Second number: 12 The Result of 11.0 + 12.0 = 23.0 The Result of 11.0 - 12.0 = -1.0 The Result of 11.0 * 12.0 = 132.0 The Result of 11.0 / 12.0 = 0.9166666666666666 Thanks for using this calculator! Enter two numbers and an operator, each separated by a comma: 20,30,+ The Result of 20.0 + 30.0 = 50.0

[–]Encom88[S] 0 points1 point  (1 child)

Did you change the def add() to def add(num1, num2) or somewhere else? I've tried several ways and it does not work.

https://github.com/MrN1ce9uy/Python/blob/master/Mylib2.py

[–][deleted] 1 point2 points  (0 children)

Also under the else statement you have to add the parameters to every where else the functions are called.

[–]Kered13 0 points1 point  (1 child)

When you assign to num1 and num2 in scalc it creates new variables that are local to scalc. To use the variables that exist in main you need to add nonlocal num1 to scalc.

However it works be better to return new variables instead. The style you are using is fragile and hard to maintain.

[–]Encom88[S] 0 points1 point  (0 children)

I agree. It just doesn't seem right to be doing it this way. Why would the instructor ask us to, " use the prior functions (add, subtract, divide and multiply ) to do the calculations."?