This question has already been solved: Start a new discussion instead

2

Contributors2

Replies6

Views11 Hours

Discussion SpanLast Updated by Lardmeister

Question

Answered

Answered

1

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:

- Add two numbers
- Subtract two numbers
- Multiply two number
- Divide two numbers

Choose: 1

Provide first number: 1

Provide second number: 2 - Add two numbers
- Subtract two numbers
- Multiply two number
- Divide two numbers

Choose:

It doesnt give me the answer. Any ideas as to why?

(This is my second program in python)

Question Self-Answered as of 2 Years Ago

You

This question has already been solved: Start a new discussion instead

View similar articles that have also been tagged: