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")


#main()    
while True:
    dispMenu()
    cmd = getCommand()
    execute(cmd)

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
    Choose:

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

Problem solved, I needed the inputs to be parsed as ints.

A common mistake!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.