1.11M Members

I have this code so far

``````#Add two digits
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:

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

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

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

print ("1. Add two numbers")
print ("2. Subtract two numbers")
print ("3. Multiply two number")
print ("4. Divide two numbers")

#main()
while True:
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.

Question Self-Answered as of 1 Year Ago

A common mistake!

You
This question has already been solved: Start a new discussion instead
Post:
View similar articles that have also been tagged: