Python Forum

Full Version: Need help with the program its not working
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
#!/usr/bin/env python3

# Simple Calculator

# Function to subtract
def subtract(x, y):
   return int(x) - int(y)

# Function to multiply
def multiply(x, y):
   return int(x) * int(y)

# Function to add
def add(x, y):
   return int(x) + int(y)

# Function to divide
def divide(x, y):
   return int(x) / int(y)

# Show a menu
print("Select operation.")
print("1.Add")
print("2.Subtract")
print("3.Multiply")
print("4.Divide")

# ASk for user input
choice = input("Enter choice(1/2/3/4):")

# ASk for two numbers and Turn input strings to integers
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))

# Check the choice and send the values to the correct function
if choice == 1:
   print(num1,"+",num2,"=", add(num1,num2))

elif choice == 2:
   print(num1,"-",num2,"=", subtract(num1,num2))

elif choice == 3:
   print(num1,"*",num2,"=", multiply(num1,num2))

elif choice == 4:
   print(num1,"/",num2,"=", divide(num1,num2))
else:
   print("Invalid input")
i also need to know tha the answer would be to this question?



After fixing the function, test it using the numbers 10 and 46. What is the last line of the output?
First of all, use Python tags when posting code. See the BBCode link for instructions on how to do that. I did it for you this time.

Second of all, we're not here to do your homework. You are going to have to show some effort. You tell us what is wrong with the program.