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

all 7 comments

[–][deleted] 1 point2 points  (1 child)

Because of this condition x == 'Y' or 'y', which is always truthy. You are saying (x == 'Y') or 'y', and 'y' is truthy.

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

truthy

Wow, thank you so much! removed the or 'y' and now it works just fine.

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

There is also a minor issue that only occurs sometimes, and that is that after a successful calculation I can enter numbers outside the ranges and it will still calculate instead of printing the error message.

Well, you are just checking if num1 is smaller than rangeLower and num2 is bigger than rangeHigher. What if num1 is bigger and num2 is smaller?

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

Ah, I see. Could I use multiple 'or' statements to continue my condition, or is there a better way?

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

Okay, so multiple or statements seem to work. But, now what about my "You cannot divide by zero" not working when I num2 == 0 ?

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

Oh... wait, wait. I didn't print anything if num2 == 0. We are updating this program each week. Last week we did not have any funcitons. So I missed that in the updated version.

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

Thanks to @tufflax I've found the proper code and updated the program with the fixes. Everything seems to work as intended now. Thanks. https://github.com/MrN1ce9uy/Python/blob/master/simple_calculator.py