I have this code so far

#Add two digits
def add(a,b):
    return a+b

#Subtract two digits
def sub(a,b):
    return a-b

#Multiply two digits
def mul(a,b):
    return a*b

#Divide two digits
def div(a,b):
    return a/b

#returns an integer that the user enters
def getCommand():
    cmd = input("Choose: ")
    return cmd

#Execute the command given
def execute(cmd):   
    a = input("Provide first number: ")
    b = input("Provide second number: ")

    if cmd == 1:
        print (add(a,b))

    if cmd == 2:
        print (sub(a,b))

    if cmd == 3:
        print (mul(a,b))

    if cmd == 4:
        print (div(a,b))

#displays the menu
def dispMenu():
    print ("1. Add two numbers")
    print ("2. Subtract two numbers")
    print ("3. Multiply two number")
    print ("4. Divide two numbers")

while True:
    cmd = getCommand()

However, when its ran, it gives the following:

  1. Add two numbers
  2. Subtract two numbers
  3. Multiply two number
  4. Divide two numbers
    Choose: 1
    Provide first number: 1
    Provide second number: 2
  5. Add two numbers
  6. Subtract two numbers
  7. Multiply two number
  8. Divide two numbers

It doesnt give me the answer. Any ideas as to why?
(This is my second program in python)

4 Years
Discussion Span
Last Post by Lardmeister
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.