Python Forum
Need help with simple calculator.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help with simple calculator.
#1
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.
Reply
#2
https://python-forum.io/Thread-Multiple-...or-keyword
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
Thank you good sir :)
Reply
#4
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) ")
 
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Simple Calculator Help destr0yer667 1 3,524 May-22-2019, 02:11 PM
Last Post: ichabod801
  Help with simple tip calculator DragonG 5 5,406 Oct-23-2018, 04:54 AM
Last Post: snippsat
  Python Program to Make a Simple Calculator jack_sparrow007 2 10,217 Oct-19-2018, 08:32 AM
Last Post: volcano63

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020