![]() |
Need help with simple calculator. - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Need help with simple calculator. (/thread-12773.html) |
Need help with simple calculator. - ghost0fkarma - Sep-11-2018 def main(): choice = input("Add or Sub? ") if choice == "Add": Add1() else: Sub1() def Add1(): addchoice = str(input("Pick a number. ")) addchoice1 = str(input("Pick another number. ")) addconv = int(addchoice) + int(addchoice1) addconv1 = str(addconv) print("Your answer is:" + " " + addconv1) exitcom() def Sub1(): subchoice = str(input("Pick a number. ")) subchoice1 = str(input("Pick another number. ")) subconv = int(subchoice) - int(subchoice1) subconv1 = str(subconv) print("Your answer is:" + " " + subconv1) main() def exitcom(): exitcom1 = input("Would you like to make another calculation? (Y/N) --> ") if exitcom1 == "Y" or "y": main() if exitcom1 == "n" or "N": exit() main()When running exitcom(), no matter if I type "y" or "n" I'm always returned back to main(). I want it to kill the program when n is type. RE: Need help with simple calculator. - buran - Sep-11-2018 https://python-forum.io/Thread-Multiple-expressions-with-or-keyword RE: Need help with simple calculator. - ghost0fkarma - Sep-11-2018 Thank you good sir :) RE: Need help with simple calculator. - woooee - Sep-11-2018 Lay it out this way def Add1(): addchoice = input("Pick a number. ") print("addchoice is a", type(addchoice)) addchoice1 = input("Pick another number. ") addconv = int(addchoice) + int(addchoice1) ## addconv1 = str(addconv) print("Your answer is: ", addconv) ## exitcom() def Sub1(): subchoice = input("Pick a number. ") subchoice1 = input("Pick another number. ") subconv = int(subchoice) - int(subchoice1) ## subconv1 = str(subconv) print("Your answer is: ", subconv) ## main() again="y" while again.lower() == "y": choice = input("Add or Sub? ") if choice in ("Add", "Sub"): if choice == "Add": Add1() else: Sub1() else: print("Not a valid option") again=input("Would you like to play again? (y or n) ") |